From df96159df04353cc106933d8a87b03afcbb768d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 19 May 2025 14:14:14 +0200 Subject: [PATCH] client/request: use containerd errdefs checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- client/request.go | 6 ++---- client/request_test.go | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/client/request.go b/client/request.go index dd95653a79..80e6d03a57 100644 --- a/client/request.go +++ b/client/request.go @@ -116,10 +116,8 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u resp, err := cli.doRequest(req) switch { - case errors.Is(err, context.Canceled): - return nil, errdefs.Cancelled(err) - case errors.Is(err, context.DeadlineExceeded): - return nil, errdefs.Deadline(err) + case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded): + return nil, err case err == nil: return resp, cli.checkResponseErr(resp) default: diff --git a/client/request_test.go b/client/request_test.go index 5be16ff876..c6bf359b9f 100644 --- a/client/request_test.go +++ b/client/request_test.go @@ -12,9 +12,9 @@ import ( "testing" "time" + cerrdefs "github.com/containerd/errdefs" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" - "github.com/docker/docker/errdefs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -91,7 +91,7 @@ func TestPlainTextError(t *testing.T) { client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")), } _, err := client.ContainerList(context.Background(), container.ListOptions{}) - assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) + assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) } // TestResponseErrors tests handling of error responses returned by the API. @@ -221,7 +221,7 @@ func TestResponseErrors(t *testing.T) { } _, err := client.Ping(context.Background()) assert.Check(t, is.Error(err, tc.expected)) - assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter)) + assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument)) }) } } @@ -240,7 +240,7 @@ func TestInfiniteError(t *testing.T) { } _, err := client.Ping(context.Background()) - assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) + assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) assert.Check(t, is.ErrorContains(err, "request returned Internal Server Error")) } @@ -258,7 +258,6 @@ func TestCanceledContext(t *testing.T) { cancel() _, err := client.sendRequest(ctx, http.MethodGet, testEndpoint, nil, nil, nil) - assert.Check(t, is.ErrorType(err, errdefs.IsCancelled)) assert.Check(t, is.ErrorIs(err, context.Canceled)) } @@ -278,6 +277,5 @@ func TestDeadlineExceededContext(t *testing.T) { <-ctx.Done() _, err := client.sendRequest(ctx, http.MethodGet, testEndpoint, nil, nil, nil) - assert.Check(t, is.ErrorType(err, errdefs.IsDeadline)) assert.Check(t, is.ErrorIs(err, context.DeadlineExceeded)) }