libnetwork: remove UnknownNetworkError

It was only returned in 2 places, and not used any different than
a "notfound" error, so let's use a standard errdefs.NotFound

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-01-22 23:15:30 +01:00
parent 8f4c98e1eb
commit 5c1fe287fc
3 changed files with 4 additions and 17 deletions

View File

@@ -56,20 +56,6 @@ func (nnr NetworkNameError) Error() string {
// Conflict denotes the type of this error
func (nnr NetworkNameError) Conflict() {}
// UnknownNetworkError is returned when libnetwork could not find in its database
// a network with the same name and id.
type UnknownNetworkError struct {
name string
id string
}
func (une *UnknownNetworkError) Error() string {
return fmt.Sprintf("unknown network %s id %s", une.name, une.id)
}
// NotFound denotes the type of this error
func (une *UnknownNetworkError) NotFound() {}
// ActiveEndpointsError is returned when a network is deleted which has active
// endpoints in it.
type ActiveEndpointsError struct {

View File

@@ -24,7 +24,7 @@ func TestErrorInterfaces(t *testing.T) {
}
}
notFoundErrorList := []error{&UnknownNetworkError{}, ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
notFoundErrorList := []error{ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
for _, err := range notFoundErrorList {
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
}

View File

@@ -16,6 +16,7 @@ import (
"time"
"github.com/containerd/log"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/libnetwork/datastore"
"github.com/docker/docker/libnetwork/driverapi"
"github.com/docker/docker/libnetwork/internal/netiputil"
@@ -1021,7 +1022,7 @@ func (n *Network) delete(force bool, rmLBEndpoint bool) error {
n, err := c.getNetworkFromStore(id)
if err != nil {
return &UnknownNetworkError{name: name, id: id}
return errdefs.NotFound(fmt.Errorf("unknown network %s id %s", name, id))
}
// Only remove ingress on force removal or explicit LB endpoint removal
@@ -1054,7 +1055,7 @@ func (n *Network) delete(force bool, rmLBEndpoint bool) error {
// Reload the network from the store to update the epcnt.
n, err = c.getNetworkFromStore(id)
if err != nil {
return &UnknownNetworkError{name: name, id: id}
return errdefs.NotFound(fmt.Errorf("unknown network %s id %s", name, id))
}
}