Merge pull request #50688 from thaJeztah/remove_errdefs_aliases

daemon/libnetwork/types: remove errdefs aliases
This commit is contained in:
Sebastiaan van Stijn
2025-08-11 19:01:55 +02:00
committed by GitHub
7 changed files with 21 additions and 33 deletions

View File

@@ -1018,7 +1018,7 @@ func (c *Controller) NewSandbox(ctx context.Context, containerID string, options
// GetSandbox returns the Sandbox which has the passed id.
//
// It returns an [ErrInvalidID] when passing an invalid ID, or an
// [types.NotFoundError] if no Sandbox was found for the container.
// [errdefs.ErrNotFound] if no Sandbox was found for the container.
func (c *Controller) GetSandbox(containerID string) (*Sandbox, error) {
if containerID == "" {
return nil, types.InvalidParameterErrorf("invalid id: id is empty")
@@ -1042,7 +1042,7 @@ func (c *Controller) GetSandbox(containerID string) (*Sandbox, error) {
}
// SandboxByID returns the Sandbox which has the passed id.
// If not found, a [types.NotFoundError] is returned.
// If not found, a [errdefs.NotFoundError] is returned.
func (c *Controller) SandboxByID(id string) (*Sandbox, error) {
if id == "" {
return nil, types.InvalidParameterErrorf("invalid id: id is empty")

View File

@@ -12,6 +12,7 @@ import (
"strconv"
"testing"
cerrdefs "github.com/containerd/errdefs"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/moby/moby/v2/daemon/libnetwork/driverapi"
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge/internal/firewaller"
@@ -555,7 +556,7 @@ func TestCreate(t *testing.T) {
if err == nil {
t.Fatal("Expected bridge driver to refuse creation of second network with default name")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatal("Creation of second network with default name failed with unexpected error type")
}
}

View File

@@ -4,7 +4,7 @@ import (
"context"
"testing"
"github.com/moby/moby/v2/daemon/libnetwork/types"
cerrdefs "github.com/containerd/errdefs"
)
func TestDriver(t *testing.T) {
@@ -27,7 +27,7 @@ func TestDriver(t *testing.T) {
if err == nil {
t.Fatal("Second network creation should fail on this driver")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatal("Second network creation failed with unexpected error type")
}
@@ -35,7 +35,7 @@ func TestDriver(t *testing.T) {
if err == nil {
t.Fatal("network deletion should fail on this driver")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatal("network deletion failed with unexpected error type")
}
@@ -44,7 +44,7 @@ func TestDriver(t *testing.T) {
if err == nil {
t.Fatal("any network deletion should fail on this driver")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatal("any network deletion failed with unexpected error type")
}
}

View File

@@ -4,7 +4,7 @@ import (
"context"
"testing"
"github.com/moby/moby/v2/daemon/libnetwork/types"
cerrdefs "github.com/containerd/errdefs"
)
func TestDriver(t *testing.T) {
@@ -27,7 +27,7 @@ func TestDriver(t *testing.T) {
if err == nil {
t.Fatalf("Second network creation should fail on this driver")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatalf("Second network creation failed with unexpected error type")
}
@@ -35,7 +35,7 @@ func TestDriver(t *testing.T) {
if err == nil {
t.Fatalf("network deletion should fail on this driver")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatalf("network deletion failed with unexpected error type")
}
@@ -44,7 +44,7 @@ func TestDriver(t *testing.T) {
if err == nil {
t.Fatalf("any network deletion should fail on this driver")
}
if _, ok := err.(types.ForbiddenError); !ok {
if !cerrdefs.IsPermissionDenied(err) {
t.Fatalf("any network deletion failed with unexpected error type")
}
}

View File

@@ -10,6 +10,7 @@ import (
"strings"
"sync"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/moby/moby/v2/daemon/internal/sliceutil"
"github.com/moby/moby/v2/daemon/internal/stringid"
@@ -988,7 +989,7 @@ func (ep *Endpoint) deleteEndpoint(force bool) error {
}
if err := driver.DeleteEndpoint(n.id, epid); err != nil {
if _, ok := err.(types.ForbiddenError); ok {
if cerrdefs.IsPermissionDenied(err) {
return err
}

View File

@@ -12,6 +12,7 @@ import (
"sync"
"time"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/moby/moby/v2/daemon/internal/sliceutil"
"github.com/moby/moby/v2/daemon/internal/stringid"
@@ -1141,7 +1142,7 @@ func (n *Network) deleteNetwork() error {
if err := d.DeleteNetwork(n.ID()); err != nil {
// Forbidden Errors should be honored
if _, ok := err.(types.ForbiddenError); ok {
if cerrdefs.IsPermissionDenied(err) {
return err
}

View File

@@ -389,21 +389,6 @@ type MaskableError interface {
Maskable()
}
// InvalidParameterError is an interface for errors originated by a bad request
type InvalidParameterError = errdefs.ErrInvalidParameter
// NotFoundError is an interface for errors raised because a needed resource is not available
type NotFoundError = errdefs.ErrNotFound
// ForbiddenError is an interface for errors which denote a valid request that cannot be honored
type ForbiddenError = errdefs.ErrForbidden
// UnavailableError is an interface for errors returned when the required service is not available
type UnavailableError = errdefs.ErrUnavailable
// NotImplementedError is an interface for errors raised because of requested functionality is not yet implemented
type NotImplementedError = errdefs.ErrNotImplemented
// InternalError is an interface for errors raised because of an internal error
type InternalError interface {
// Internal makes implementer into InternalError type
@@ -414,27 +399,27 @@ type InternalError interface {
* Well-known Error Formatters
******************************/
// InvalidParameterErrorf creates an instance of InvalidParameterError
// InvalidParameterErrorf creates an instance of [errdefs.ErrInvalidParameter].
func InvalidParameterErrorf(format string, params ...any) error {
return errdefs.InvalidParameter(fmt.Errorf(format, params...))
}
// NotFoundErrorf creates an instance of NotFoundError
// NotFoundErrorf creates an instance of [errdefs.ErrNotFound].
func NotFoundErrorf(format string, params ...any) error {
return errdefs.NotFound(fmt.Errorf(format, params...))
}
// ForbiddenErrorf creates an instance of ForbiddenError
// ForbiddenErrorf creates an instance of [errdefs.ErrForbidden].
func ForbiddenErrorf(format string, params ...any) error {
return errdefs.Forbidden(fmt.Errorf(format, params...))
}
// UnavailableErrorf creates an instance of UnavailableError
// UnavailableErrorf creates an instance of [errdefs.ErrUnavailable]
func UnavailableErrorf(format string, params ...any) error {
return errdefs.Unavailable(fmt.Errorf(format, params...))
}
// NotImplementedErrorf creates an instance of NotImplementedError
// NotImplementedErrorf creates an instance of [errdefs.ErrNotImplemented].
func NotImplementedErrorf(format string, params ...any) error {
return errdefs.NotImplemented(fmt.Errorf(format, params...))
}