Browse code

libnetwork: remove ErrInvalidID

It was only returned in a few places, and not used any different than
a "invalid parameter" error, so let's use a standard errdefs.ErrInvalidParameter

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/01/27 17:55:02
Showing 4 changed files
... ...
@@ -860,7 +860,7 @@ func (c *Controller) NetworkByName(name string) (*Network, error) {
860 860
 // If not found, the error [ErrNoSuchNetwork] is returned.
861 861
 func (c *Controller) NetworkByID(id string) (*Network, error) {
862 862
 	if id == "" {
863
-		return nil, ErrInvalidID(id)
863
+		return nil, types.InvalidParameterErrorf("invalid id: id is empty")
864 864
 	}
865 865
 	return c.getNetworkFromStore(id)
866 866
 }
... ...
@@ -974,7 +974,7 @@ func (c *Controller) NewSandbox(ctx context.Context, containerID string, options
974 974
 // [types.NotFoundError] if no Sandbox was found for the container.
975 975
 func (c *Controller) GetSandbox(containerID string) (*Sandbox, error) {
976 976
 	if containerID == "" {
977
-		return nil, ErrInvalidID("id is empty")
977
+		return nil, types.InvalidParameterErrorf("invalid id: id is empty")
978 978
 	}
979 979
 	c.mu.Lock()
980 980
 	defer c.mu.Unlock()
... ...
@@ -998,7 +998,7 @@ func (c *Controller) GetSandbox(containerID string) (*Sandbox, error) {
998 998
 // If not found, a [types.NotFoundError] is returned.
999 999
 func (c *Controller) SandboxByID(id string) (*Sandbox, error) {
1000 1000
 	if id == "" {
1001
-		return nil, ErrInvalidID(id)
1001
+		return nil, types.InvalidParameterErrorf("invalid id: id is empty")
1002 1002
 	}
1003 1003
 	c.mu.Lock()
1004 1004
 	s, ok := c.sandboxes[id]
... ...
@@ -14,17 +14,6 @@ func (nsn ErrNoSuchNetwork) Error() string {
14 14
 // NotFound denotes the type of this error
15 15
 func (nsn ErrNoSuchNetwork) NotFound() {}
16 16
 
17
-// ErrInvalidID is returned when a query-by-id method is being invoked
18
-// with an empty id parameter
19
-type ErrInvalidID string
20
-
21
-func (ii ErrInvalidID) Error() string {
22
-	return fmt.Sprintf("invalid id: %s", string(ii))
23
-}
24
-
25
-// InvalidParameter denotes the type of this error
26
-func (ii ErrInvalidID) InvalidParameter() {}
27
-
28 17
 // ErrInvalidName is returned when a query-by-name or resource create method is
29 18
 // invoked with an empty name parameter
30 19
 type ErrInvalidName string
... ...
@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestErrorInterfaces(t *testing.T) {
13
-	badRequestErrorList := []error{ErrInvalidID(""), ErrInvalidName("")}
13
+	badRequestErrorList := []error{ErrInvalidName("")}
14 14
 	for _, err := range badRequestErrorList {
15 15
 		assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
16 16
 	}
... ...
@@ -552,7 +552,7 @@ func TestControllerQuery(t *testing.T) {
552 552
 
553 553
 	_, err = controller.NetworkByID("")
554 554
 	assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
555
-	assert.Check(t, is.ErrorContains(err, "invalid id:"))
555
+	assert.Check(t, is.Error(err, "invalid id: id is empty"))
556 556
 
557 557
 	g, err := controller.NetworkByID("network1")
558 558
 	assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))