mirror of
https://github.com/moby/moby.git
synced 2026-01-10 18:21:35 +00:00
errdefs: remove deprecated IsXXX utilities
These were deprecated in f1bb44aeee, and
the IsContext is no longer used. They are not carried forward in the
new module.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
package errdefs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// FromStatusCode creates an errdef error, based on the provided HTTP status-code
|
||||
//
|
||||
// Deprecated: Use [cerrdefs.ToNative] instead
|
||||
func FromStatusCode(err error, statusCode int) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
switch statusCode {
|
||||
case http.StatusNotFound:
|
||||
return NotFound(err)
|
||||
case http.StatusBadRequest:
|
||||
return InvalidParameter(err)
|
||||
case http.StatusConflict:
|
||||
return Conflict(err)
|
||||
case http.StatusUnauthorized:
|
||||
return Unauthorized(err)
|
||||
case http.StatusServiceUnavailable:
|
||||
return Unavailable(err)
|
||||
case http.StatusForbidden:
|
||||
return Forbidden(err)
|
||||
case http.StatusNotModified:
|
||||
return NotModified(err)
|
||||
case http.StatusNotImplemented:
|
||||
return NotImplemented(err)
|
||||
case http.StatusInternalServerError:
|
||||
if IsCancelled(err) || IsSystem(err) || IsUnknown(err) || IsDataLoss(err) || IsDeadline(err) {
|
||||
return err
|
||||
}
|
||||
return System(err)
|
||||
default:
|
||||
switch {
|
||||
case statusCode >= http.StatusOK && statusCode < http.StatusBadRequest:
|
||||
// it's a client error
|
||||
return err
|
||||
case statusCode >= http.StatusBadRequest && statusCode < http.StatusInternalServerError:
|
||||
return InvalidParameter(err)
|
||||
case statusCode >= http.StatusInternalServerError && statusCode < 600:
|
||||
return System(err)
|
||||
default:
|
||||
return Unknown(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package errdefs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFromStatusCode(t *testing.T) {
|
||||
testErr := errors.New("some error occurred")
|
||||
|
||||
testCases := []struct {
|
||||
err error
|
||||
status int
|
||||
check func(error) bool
|
||||
}{
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusNotFound,
|
||||
check: IsNotFound,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusBadRequest,
|
||||
check: IsInvalidParameter,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusConflict,
|
||||
check: IsConflict,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusUnauthorized,
|
||||
check: IsUnauthorized,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusServiceUnavailable,
|
||||
check: IsUnavailable,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusForbidden,
|
||||
check: IsForbidden,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusNotModified,
|
||||
check: IsNotModified,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusNotImplemented,
|
||||
check: IsNotImplemented,
|
||||
},
|
||||
{
|
||||
err: testErr,
|
||||
status: http.StatusInternalServerError,
|
||||
check: IsSystem,
|
||||
},
|
||||
{
|
||||
err: Unknown(testErr),
|
||||
status: http.StatusInternalServerError,
|
||||
check: IsUnknown,
|
||||
},
|
||||
{
|
||||
err: DataLoss(testErr),
|
||||
status: http.StatusInternalServerError,
|
||||
check: IsDataLoss,
|
||||
},
|
||||
{
|
||||
err: Deadline(testErr),
|
||||
status: http.StatusInternalServerError,
|
||||
check: IsDeadline,
|
||||
},
|
||||
{
|
||||
err: Cancelled(testErr),
|
||||
status: http.StatusInternalServerError,
|
||||
check: IsCancelled,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(http.StatusText(tc.status), func(t *testing.T) {
|
||||
//nolint:staticcheck // ignore SA1019: FromStatusCode is deprecated
|
||||
err := FromStatusCode(tc.err, tc.status)
|
||||
if !tc.check(err) {
|
||||
t.Errorf("unexpected error-type %T", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package errdefs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
)
|
||||
|
||||
// IsNotFound returns if the passed in error is an [ErrNotFound],
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsNotFound]
|
||||
var IsNotFound = cerrdefs.IsNotFound
|
||||
|
||||
// IsInvalidParameter returns if the passed in error is an [ErrInvalidParameter].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsInvalidArgument]
|
||||
var IsInvalidParameter = cerrdefs.IsInvalidArgument
|
||||
|
||||
// IsConflict returns if the passed in error is an [ErrConflict].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsConflict]
|
||||
var IsConflict = cerrdefs.IsConflict
|
||||
|
||||
// IsUnauthorized returns if the passed in error is an [ErrUnauthorized].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsUnauthorized]
|
||||
var IsUnauthorized = cerrdefs.IsUnauthorized
|
||||
|
||||
// IsUnavailable returns if the passed in error is an [ErrUnavailable].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsUnavailable]
|
||||
var IsUnavailable = cerrdefs.IsUnavailable
|
||||
|
||||
// IsForbidden returns if the passed in error is an [ErrForbidden].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsPermissionDenied]
|
||||
var IsForbidden = cerrdefs.IsPermissionDenied
|
||||
|
||||
// IsSystem returns if the passed in error is an [ErrSystem].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsInternal]
|
||||
var IsSystem = cerrdefs.IsInternal
|
||||
|
||||
// IsNotModified returns if the passed in error is an [ErrNotModified].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsNotModified]
|
||||
var IsNotModified = cerrdefs.IsNotModified
|
||||
|
||||
// IsNotImplemented returns if the passed in error is an [ErrNotImplemented].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsNotImplemented]
|
||||
var IsNotImplemented = cerrdefs.IsNotImplemented
|
||||
|
||||
// IsUnknown returns if the passed in error is an [ErrUnknown].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsUnknown]
|
||||
var IsUnknown = cerrdefs.IsUnknown
|
||||
|
||||
// IsCancelled returns if the passed in error is an [ErrCancelled].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsCanceled]
|
||||
var IsCancelled = cerrdefs.IsCanceled
|
||||
|
||||
// IsDeadline returns if the passed in error is an [ErrDeadline].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsDeadlineExceeded]
|
||||
var IsDeadline = cerrdefs.IsDeadlineExceeded
|
||||
|
||||
// IsDataLoss returns if the passed in error is an [ErrDataLoss].
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsDataLoss]
|
||||
var IsDataLoss = cerrdefs.IsDataLoss
|
||||
|
||||
// IsContext returns if the passed in error is due to context cancellation or deadline exceeded.
|
||||
func IsContext(err error) bool {
|
||||
return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
|
||||
}
|
||||
Reference in New Issue
Block a user