Browse code

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>

Sebastiaan van Stijn authored on 2025/01/23 07:15:30
Showing 3 changed files
... ...
@@ -56,20 +56,6 @@ func (nnr NetworkNameError) Error() string {
56 56
 // Conflict denotes the type of this error
57 57
 func (nnr NetworkNameError) Conflict() {}
58 58
 
59
-// UnknownNetworkError is returned when libnetwork could not find in its database
60
-// a network with the same name and id.
61
-type UnknownNetworkError struct {
62
-	name string
63
-	id   string
64
-}
65
-
66
-func (une *UnknownNetworkError) Error() string {
67
-	return fmt.Sprintf("unknown network %s id %s", une.name, une.id)
68
-}
69
-
70
-// NotFound denotes the type of this error
71
-func (une *UnknownNetworkError) NotFound() {}
72
-
73 59
 // ActiveEndpointsError is returned when a network is deleted which has active
74 60
 // endpoints in it.
75 61
 type ActiveEndpointsError struct {
... ...
@@ -24,7 +24,7 @@ func TestErrorInterfaces(t *testing.T) {
24 24
 		}
25 25
 	}
26 26
 
27
-	notFoundErrorList := []error{&UnknownNetworkError{}, ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
27
+	notFoundErrorList := []error{ErrNoSuchNetwork(""), ErrNoSuchEndpoint("")}
28 28
 	for _, err := range notFoundErrorList {
29 29
 		assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
30 30
 	}
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"time"
17 17
 
18 18
 	"github.com/containerd/log"
19
+	"github.com/docker/docker/errdefs"
19 20
 	"github.com/docker/docker/libnetwork/datastore"
20 21
 	"github.com/docker/docker/libnetwork/driverapi"
21 22
 	"github.com/docker/docker/libnetwork/internal/netiputil"
... ...
@@ -1021,7 +1022,7 @@ func (n *Network) delete(force bool, rmLBEndpoint bool) error {
1021 1021
 
1022 1022
 	n, err := c.getNetworkFromStore(id)
1023 1023
 	if err != nil {
1024
-		return &UnknownNetworkError{name: name, id: id}
1024
+		return errdefs.NotFound(fmt.Errorf("unknown network %s id %s", name, id))
1025 1025
 	}
1026 1026
 
1027 1027
 	// Only remove ingress on force removal or explicit LB endpoint removal
... ...
@@ -1054,7 +1055,7 @@ func (n *Network) delete(force bool, rmLBEndpoint bool) error {
1054 1054
 		// Reload the network from the store to update the epcnt.
1055 1055
 		n, err = c.getNetworkFromStore(id)
1056 1056
 		if err != nil {
1057
-			return &UnknownNetworkError{name: name, id: id}
1057
+			return errdefs.NotFound(fmt.Errorf("unknown network %s id %s", name, id))
1058 1058
 		}
1059 1059
 	}
1060 1060