InvalidParameter is now compatible with errdefs.InvalidParameter. Thus,
these errors will now return a 400 status code instead of a 500.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
| ... | ... |
@@ -845,7 +845,7 @@ func (c *Controller) NetworkByID(id string) (*Network, error) {
|
| 845 | 845 |
// NewSandbox creates a new sandbox for containerID. |
| 846 | 846 |
func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (*Sandbox, error) {
|
| 847 | 847 |
if containerID == "" {
|
| 848 |
- return nil, types.BadRequestErrorf("invalid container ID")
|
|
| 848 |
+ return nil, types.InvalidParameterErrorf("invalid container ID")
|
|
| 849 | 849 |
} |
| 850 | 850 |
|
| 851 | 851 |
var sb *Sandbox |
| ... | ... |
@@ -1105,7 +1105,7 @@ func (c *Controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capabili |
| 1105 | 1105 |
// Now that we resolved the plugin, try again looking up the registry |
| 1106 | 1106 |
id, cap = c.ipamRegistry.IPAM(name) |
| 1107 | 1107 |
if id == nil {
|
| 1108 |
- return nil, nil, types.BadRequestErrorf("invalid ipam driver: %q", name)
|
|
| 1108 |
+ return nil, nil, types.InvalidParameterErrorf("invalid ipam driver: %q", name)
|
|
| 1109 | 1109 |
} |
| 1110 | 1110 |
} |
| 1111 | 1111 |
|
| ... | ... |
@@ -221,13 +221,13 @@ func (ds *Store) PutObjectAtomic(kvObject KVObject) error {
|
| 221 | 221 |
defer ds.mu.Unlock() |
| 222 | 222 |
|
| 223 | 223 |
if kvObject == nil {
|
| 224 |
- return types.BadRequestErrorf("invalid KV Object : nil")
|
|
| 224 |
+ return types.InvalidParameterErrorf("invalid KV Object : nil")
|
|
| 225 | 225 |
} |
| 226 | 226 |
|
| 227 | 227 |
kvObjValue := kvObject.Value() |
| 228 | 228 |
|
| 229 | 229 |
if kvObjValue == nil {
|
| 230 |
- return types.BadRequestErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...))
|
|
| 230 |
+ return types.InvalidParameterErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...))
|
|
| 231 | 231 |
} |
| 232 | 232 |
|
| 233 | 233 |
if kvObject.Skip() {
|
| ... | ... |
@@ -375,7 +375,7 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error {
|
| 375 | 375 |
defer ds.mu.Unlock() |
| 376 | 376 |
|
| 377 | 377 |
if kvObject == nil {
|
| 378 |
- return types.BadRequestErrorf("invalid KV Object : nil")
|
|
| 378 |
+ return types.InvalidParameterErrorf("invalid KV Object : nil")
|
|
| 379 | 379 |
} |
| 380 | 380 |
|
| 381 | 381 |
previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()}
|
| ... | ... |
@@ -62,14 +62,14 @@ func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPai |
| 62 | 62 |
|
| 63 | 63 |
if previous == nil {
|
| 64 | 64 |
if mData != nil {
|
| 65 |
- return nil, types.BadRequestErrorf("atomic put failed because key exists")
|
|
| 65 |
+ return nil, types.InvalidParameterErrorf("atomic put failed because key exists")
|
|
| 66 | 66 |
} // Else OK. |
| 67 | 67 |
} else {
|
| 68 | 68 |
if mData == nil {
|
| 69 |
- return nil, types.BadRequestErrorf("atomic put failed because key exists")
|
|
| 69 |
+ return nil, types.InvalidParameterErrorf("atomic put failed because key exists")
|
|
| 70 | 70 |
} |
| 71 | 71 |
if mData != nil && mData.Index != previous.LastIndex {
|
| 72 |
- return nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
|
|
| 72 |
+ return nil, types.InvalidParameterErrorf("atomic put failed due to mismatched Index")
|
|
| 73 | 73 |
} // Else OK. |
| 74 | 74 |
} |
| 75 | 75 |
if err := s.Put(key, newValue); err != nil {
|
| ... | ... |
@@ -83,7 +83,7 @@ func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPai |
| 83 | 83 |
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) error {
|
| 84 | 84 |
mData := s.db[key] |
| 85 | 85 |
if mData != nil && mData.Index != previous.LastIndex {
|
| 86 |
- return types.BadRequestErrorf("atomic delete failed due to mismatched Index")
|
|
| 86 |
+ return types.InvalidParameterErrorf("atomic delete failed due to mismatched Index")
|
|
| 87 | 87 |
} |
| 88 | 88 |
delete(s.db, key) |
| 89 | 89 |
return nil |
| ... | ... |
@@ -68,26 +68,26 @@ func (i *IPAMData) UnmarshalJSON(data []byte) error {
|
| 68 | 68 |
func (i *IPAMData) Validate() error {
|
| 69 | 69 |
var isV6 bool |
| 70 | 70 |
if i.Pool == nil {
|
| 71 |
- return types.BadRequestErrorf("invalid pool")
|
|
| 71 |
+ return types.InvalidParameterErrorf("invalid pool")
|
|
| 72 | 72 |
} |
| 73 | 73 |
if i.Gateway == nil {
|
| 74 |
- return types.BadRequestErrorf("invalid gateway address")
|
|
| 74 |
+ return types.InvalidParameterErrorf("invalid gateway address")
|
|
| 75 | 75 |
} |
| 76 | 76 |
isV6 = i.IsV6() |
| 77 | 77 |
if isV6 && i.Gateway.IP.To4() != nil || !isV6 && i.Gateway.IP.To4() == nil {
|
| 78 |
- return types.BadRequestErrorf("incongruent ip versions for pool and gateway")
|
|
| 78 |
+ return types.InvalidParameterErrorf("incongruent ip versions for pool and gateway")
|
|
| 79 | 79 |
} |
| 80 | 80 |
for k, sip := range i.AuxAddresses {
|
| 81 | 81 |
if isV6 && sip.IP.To4() != nil || !isV6 && sip.IP.To4() == nil {
|
| 82 |
- return types.BadRequestErrorf("incongruent ip versions for pool and secondary ip address %s", k)
|
|
| 82 |
+ return types.InvalidParameterErrorf("incongruent ip versions for pool and secondary ip address %s", k)
|
|
| 83 | 83 |
} |
| 84 | 84 |
} |
| 85 | 85 |
if !i.Pool.Contains(i.Gateway.IP) {
|
| 86 |
- return types.BadRequestErrorf("invalid gateway address (%s) does not belong to the pool (%s)", i.Gateway, i.Pool)
|
|
| 86 |
+ return types.InvalidParameterErrorf("invalid gateway address (%s) does not belong to the pool (%s)", i.Gateway, i.Pool)
|
|
| 87 | 87 |
} |
| 88 | 88 |
for k, sip := range i.AuxAddresses {
|
| 89 | 89 |
if !i.Pool.Contains(sip.IP) {
|
| 90 |
- return types.BadRequestErrorf("invalid secondary address %s (%s) does not belong to the pool (%s)", k, i.Gateway, i.Pool)
|
|
| 90 |
+ return types.InvalidParameterErrorf("invalid secondary address %s (%s) does not belong to the pool (%s)", k, i.Gateway, i.Pool)
|
|
| 91 | 91 |
} |
| 92 | 92 |
} |
| 93 | 93 |
return nil |
| ... | ... |
@@ -277,7 +277,7 @@ func (c *networkConfiguration) fromLabels(labels map[string]string) error {
|
| 277 | 277 |
} |
| 278 | 278 |
|
| 279 | 279 |
func parseErr(label, value, errString string) error {
|
| 280 |
- return types.BadRequestErrorf("failed to parse %s value: %v (%s)", label, value, errString)
|
|
| 280 |
+ return types.InvalidParameterErrorf("failed to parse %s value: %v (%s)", label, value, errString)
|
|
| 281 | 281 |
} |
| 282 | 282 |
|
| 283 | 283 |
func (n *bridgeNetwork) registerIptCleanFunc(clean iptableCleanFunc) {
|
| ... | ... |
@@ -289,7 +289,7 @@ func (n *bridgeNetwork) getDriverChains(version iptables.IPVersion) (*iptables.C |
| 289 | 289 |
defer n.Unlock() |
| 290 | 290 |
|
| 291 | 291 |
if n.driver == nil {
|
| 292 |
- return nil, nil, nil, nil, types.BadRequestErrorf("no driver found")
|
|
| 292 |
+ return nil, nil, nil, nil, types.InvalidParameterErrorf("no driver found")
|
|
| 293 | 293 |
} |
| 294 | 294 |
|
| 295 | 295 |
if version == iptables.IPv6 {
|
| ... | ... |
@@ -445,7 +445,7 @@ func (d *driver) getNetwork(id string) (*bridgeNetwork, error) {
|
| 445 | 445 |
defer d.Unlock() |
| 446 | 446 |
|
| 447 | 447 |
if id == "" {
|
| 448 |
- return nil, types.BadRequestErrorf("invalid network id: %s", id)
|
|
| 448 |
+ return nil, types.InvalidParameterErrorf("invalid network id: %s", id)
|
|
| 449 | 449 |
} |
| 450 | 450 |
|
| 451 | 451 |
if nw, ok := d.networks[id]; ok {
|
| ... | ... |
@@ -476,7 +476,7 @@ func parseNetworkGenericOptions(data interface{}) (*networkConfiguration, error)
|
| 476 | 476 |
config = opaqueConfig.(*networkConfiguration) |
| 477 | 477 |
} |
| 478 | 478 |
default: |
| 479 |
- err = types.BadRequestErrorf("do not recognize network configuration format: %T", opt)
|
|
| 479 |
+ err = types.InvalidParameterErrorf("do not recognize network configuration format: %T", opt)
|
|
| 480 | 480 |
} |
| 481 | 481 |
|
| 482 | 482 |
return config, err |
| ... | ... |
@@ -488,7 +488,7 @@ func (c *networkConfiguration) processIPAM(id string, ipamV4Data, ipamV6Data []d |
| 488 | 488 |
} |
| 489 | 489 |
|
| 490 | 490 |
if len(ipamV4Data) == 0 {
|
| 491 |
- return types.BadRequestErrorf("bridge network %s requires ipv4 configuration", id)
|
|
| 491 |
+ return types.InvalidParameterErrorf("bridge network %s requires ipv4 configuration", id)
|
|
| 492 | 492 |
} |
| 493 | 493 |
|
| 494 | 494 |
if ipamV4Data[0].Gateway != nil {
|
| ... | ... |
@@ -592,7 +592,7 @@ func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (s |
| 592 | 592 |
// Create a new network using bridge plugin |
| 593 | 593 |
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
|
| 594 | 594 |
if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
|
| 595 |
- return types.BadRequestErrorf("ipv4 pool is empty")
|
|
| 595 |
+ return types.InvalidParameterErrorf("ipv4 pool is empty")
|
|
| 596 | 596 |
} |
| 597 | 597 |
// Sanity checks |
| 598 | 598 |
d.Lock() |
| ... | ... |
@@ -1479,7 +1479,7 @@ func parseConnectivityOptions(cOptions map[string]interface{}) (*connectivityCon
|
| 1479 | 1479 |
if pb, ok := opt.([]types.PortBinding); ok {
|
| 1480 | 1480 |
cc.PortBindings = pb |
| 1481 | 1481 |
} else {
|
| 1482 |
- return nil, types.BadRequestErrorf("Invalid port mapping data in connectivity configuration: %v", opt)
|
|
| 1482 |
+ return nil, types.InvalidParameterErrorf("Invalid port mapping data in connectivity configuration: %v", opt)
|
|
| 1483 | 1483 |
} |
| 1484 | 1484 |
} |
| 1485 | 1485 |
|
| ... | ... |
@@ -1487,7 +1487,7 @@ func parseConnectivityOptions(cOptions map[string]interface{}) (*connectivityCon
|
| 1487 | 1487 |
if ports, ok := opt.([]types.TransportPort); ok {
|
| 1488 | 1488 |
cc.ExposedPorts = ports |
| 1489 | 1489 |
} else {
|
| 1490 |
- return nil, types.BadRequestErrorf("Invalid exposed ports data in connectivity configuration: %v", opt)
|
|
| 1490 |
+ return nil, types.InvalidParameterErrorf("Invalid exposed ports data in connectivity configuration: %v", opt)
|
|
| 1491 | 1491 |
} |
| 1492 | 1492 |
} |
| 1493 | 1493 |
|
| ... | ... |
@@ -574,7 +574,7 @@ func (i *testInterface) SetMacAddress(mac net.HardwareAddr) error {
|
| 574 | 574 |
return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", i.mac, mac)
|
| 575 | 575 |
} |
| 576 | 576 |
if mac == nil {
|
| 577 |
- return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 577 |
+ return types.InvalidParameterErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 578 | 578 |
} |
| 579 | 579 |
i.mac = types.GetMacCopy(mac) |
| 580 | 580 |
return nil |
| ... | ... |
@@ -582,7 +582,7 @@ func (i *testInterface) SetMacAddress(mac net.HardwareAddr) error {
|
| 582 | 582 |
|
| 583 | 583 |
func (i *testInterface) SetIPAddress(address *net.IPNet) error {
|
| 584 | 584 |
if address.IP == nil {
|
| 585 |
- return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
|
|
| 585 |
+ return types.InvalidParameterErrorf("tried to set nil IP address to endpoint interface")
|
|
| 586 | 586 |
} |
| 587 | 587 |
if address.IP.To4() == nil {
|
| 588 | 588 |
return setAddress(&i.addrv6, address) |
| ... | ... |
@@ -41,8 +41,8 @@ func (eiec *ErrInvalidEndpointConfig) Error() string {
|
| 41 | 41 |
return "trying to create an endpoint with an invalid endpoint configuration" |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
-// BadRequest denotes the type of this error |
|
| 45 |
-func (eiec *ErrInvalidEndpointConfig) BadRequest() {}
|
|
| 44 |
+// InvalidParameter denotes the type of this error |
|
| 45 |
+func (eiec *ErrInvalidEndpointConfig) InvalidParameter() {}
|
|
| 46 | 46 |
|
| 47 | 47 |
// ErrNetworkExists error is returned when a network already exists and another network is created. |
| 48 | 48 |
type ErrNetworkExists struct{}
|
| ... | ... |
@@ -81,8 +81,8 @@ func (eig *ErrInvalidGateway) Error() string {
|
| 81 | 81 |
return "default gateway ip must be part of the network" |
| 82 | 82 |
} |
| 83 | 83 |
|
| 84 |
-// BadRequest denotes the type of this error |
|
| 85 |
-func (eig *ErrInvalidGateway) BadRequest() {}
|
|
| 84 |
+// InvalidParameter denotes the type of this error |
|
| 85 |
+func (eig *ErrInvalidGateway) InvalidParameter() {}
|
|
| 86 | 86 |
|
| 87 | 87 |
// ErrInvalidContainerSubnet is returned when the container subnet (FixedCIDR) is not valid. |
| 88 | 88 |
type ErrInvalidContainerSubnet struct{}
|
| ... | ... |
@@ -91,8 +91,8 @@ func (eis *ErrInvalidContainerSubnet) Error() string {
|
| 91 | 91 |
return "container subnet must be a subset of bridge network" |
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 |
-// BadRequest denotes the type of this error |
|
| 95 |
-func (eis *ErrInvalidContainerSubnet) BadRequest() {}
|
|
| 94 |
+// InvalidParameter denotes the type of this error |
|
| 95 |
+func (eis *ErrInvalidContainerSubnet) InvalidParameter() {}
|
|
| 96 | 96 |
|
| 97 | 97 |
// ErrInvalidMtu is returned when the user provided MTU is not valid. |
| 98 | 98 |
type ErrInvalidMtu int |
| ... | ... |
@@ -101,8 +101,8 @@ func (eim ErrInvalidMtu) Error() string {
|
| 101 | 101 |
return fmt.Sprintf("invalid MTU number: %d", int(eim))
|
| 102 | 102 |
} |
| 103 | 103 |
|
| 104 |
-// BadRequest denotes the type of this error |
|
| 105 |
-func (eim ErrInvalidMtu) BadRequest() {}
|
|
| 104 |
+// InvalidParameter denotes the type of this error |
|
| 105 |
+func (eim ErrInvalidMtu) InvalidParameter() {}
|
|
| 106 | 106 |
|
| 107 | 107 |
// ErrUnsupportedAddressType is returned when the specified address type is not supported. |
| 108 | 108 |
type ErrUnsupportedAddressType string |
| ... | ... |
@@ -111,8 +111,8 @@ func (uat ErrUnsupportedAddressType) Error() string {
|
| 111 | 111 |
return fmt.Sprintf("unsupported address type: %s", string(uat))
|
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 |
-// BadRequest denotes the type of this error |
|
| 115 |
-func (uat ErrUnsupportedAddressType) BadRequest() {}
|
|
| 114 |
+// InvalidParameter denotes the type of this error |
|
| 115 |
+func (uat ErrUnsupportedAddressType) InvalidParameter() {}
|
|
| 116 | 116 |
|
| 117 | 117 |
// ActiveEndpointsError is returned when there are |
| 118 | 118 |
// still active endpoints in the network being deleted. |
| ... | ... |
@@ -144,8 +144,8 @@ func (ieie InvalidEndpointIDError) Error() string {
|
| 144 | 144 |
return fmt.Sprintf("invalid endpoint id: %s", string(ieie))
|
| 145 | 145 |
} |
| 146 | 146 |
|
| 147 |
-// BadRequest denotes the type of this error |
|
| 148 |
-func (ieie InvalidEndpointIDError) BadRequest() {}
|
|
| 147 |
+// InvalidParameter denotes the type of this error |
|
| 148 |
+func (ieie InvalidEndpointIDError) InvalidParameter() {}
|
|
| 149 | 149 |
|
| 150 | 150 |
// EndpointNotFoundError is returned when the no endpoint |
| 151 | 151 |
// with the passed endpoint id is found. |
| ... | ... |
@@ -227,7 +227,7 @@ func parseNetworkGenericOptions(data interface{}) (*configuration, error) {
|
| 227 | 227 |
} |
| 228 | 228 |
return opaqueConfig.(*configuration), nil |
| 229 | 229 |
default: |
| 230 |
- return nil, types.BadRequestErrorf("unrecognized network configuration format: %v", opt)
|
|
| 230 |
+ return nil, types.InvalidParameterErrorf("unrecognized network configuration format: %v", opt)
|
|
| 231 | 231 |
} |
| 232 | 232 |
} |
| 233 | 233 |
|
| ... | ... |
@@ -94,7 +94,7 @@ func (d *driver) getNetwork(id string) (*network, error) {
|
| 94 | 94 |
d.Lock() |
| 95 | 95 |
defer d.Unlock() |
| 96 | 96 |
if id == "" {
|
| 97 |
- return nil, types.BadRequestErrorf("invalid network id: %s", id)
|
|
| 97 |
+ return nil, types.InvalidParameterErrorf("invalid network id: %s", id)
|
|
| 98 | 98 |
} |
| 99 | 99 |
|
| 100 | 100 |
if nw, ok := d.networks[id]; ok {
|
| ... | ... |
@@ -206,7 +206,7 @@ func parseNetworkGenericOptions(data interface{}) (*configuration, error) {
|
| 206 | 206 |
} |
| 207 | 207 |
return opaqueConfig.(*configuration), nil |
| 208 | 208 |
default: |
| 209 |
- return nil, types.BadRequestErrorf("unrecognized network configuration format: %v", opt)
|
|
| 209 |
+ return nil, types.InvalidParameterErrorf("unrecognized network configuration format: %v", opt)
|
|
| 210 | 210 |
} |
| 211 | 211 |
} |
| 212 | 212 |
|
| ... | ... |
@@ -93,7 +93,7 @@ func (d *driver) getNetwork(id string) (*network, error) {
|
| 93 | 93 |
d.Lock() |
| 94 | 94 |
defer d.Unlock() |
| 95 | 95 |
if id == "" {
|
| 96 |
- return nil, types.BadRequestErrorf("invalid network id: %s", id)
|
|
| 96 |
+ return nil, types.InvalidParameterErrorf("invalid network id: %s", id)
|
|
| 97 | 97 |
} |
| 98 | 98 |
if nw, ok := d.networks[id]; ok {
|
| 99 | 99 |
return nw, nil |
| ... | ... |
@@ -519,12 +519,12 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
|
| 519 | 519 |
if (newKey != nil && newIdx == -1) || |
| 520 | 520 |
(primary != nil && priIdx == -1) || |
| 521 | 521 |
(pruneKey != nil && delIdx == -1) {
|
| 522 |
- return types.BadRequestErrorf("cannot find proper key indices while processing key update:"+
|
|
| 522 |
+ return types.InvalidParameterErrorf("cannot find proper key indices while processing key update:"+
|
|
| 523 | 523 |
"(newIdx,priIdx,delIdx):(%d, %d, %d)", newIdx, priIdx, delIdx) |
| 524 | 524 |
} |
| 525 | 525 |
|
| 526 | 526 |
if priIdx != -1 && priIdx == delIdx {
|
| 527 |
- return types.BadRequestErrorf("attempting to both make a key (index %d) primary and delete it", priIdx)
|
|
| 527 |
+ return types.InvalidParameterErrorf("attempting to both make a key (index %d) primary and delete it", priIdx)
|
|
| 528 | 528 |
} |
| 529 | 529 |
|
| 530 | 530 |
d.secMapWalk(func(rIPs string, spis []*spi) ([]*spi, bool) {
|
| ... | ... |
@@ -83,7 +83,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
| 83 | 83 |
return fmt.Errorf("invalid network id")
|
| 84 | 84 |
} |
| 85 | 85 |
if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
|
| 86 |
- return types.BadRequestErrorf("ipv4 pool is empty")
|
|
| 86 |
+ return types.InvalidParameterErrorf("ipv4 pool is empty")
|
|
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
// Since we perform lazy configuration make sure we try |
| ... | ... |
@@ -128,7 +128,7 @@ func (test *testEndpoint) SetMacAddress(mac net.HardwareAddr) error {
|
| 128 | 128 |
return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", test.macAddress, mac)
|
| 129 | 129 |
} |
| 130 | 130 |
if mac == nil {
|
| 131 |
- return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 131 |
+ return types.InvalidParameterErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 132 | 132 |
} |
| 133 | 133 |
test.macAddress = mac.String() |
| 134 | 134 |
return nil |
| ... | ... |
@@ -136,7 +136,7 @@ func (test *testEndpoint) SetMacAddress(mac net.HardwareAddr) error {
|
| 136 | 136 |
|
| 137 | 137 |
func (test *testEndpoint) SetIPAddress(address *net.IPNet) error {
|
| 138 | 138 |
if address.IP == nil {
|
| 139 |
- return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
|
|
| 139 |
+ return types.InvalidParameterErrorf("tried to set nil IP address to endpoint interface")
|
|
| 140 | 140 |
} |
| 141 | 141 |
if address.IP.To4() == nil {
|
| 142 | 142 |
return setAddress(&test.addressIPv6, address) |
| ... | ... |
@@ -76,7 +76,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
|
| 79 |
- return types.BadRequestErrorf("ipv4 pool is empty")
|
|
| 79 |
+ return types.InvalidParameterErrorf("ipv4 pool is empty")
|
|
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 | 82 |
staleNetworks = make([]string, 0) |
| ... | ... |
@@ -199,7 +199,7 @@ func (d *driver) parseNetworkOptions(id string, genericOptions map[string]string |
| 199 | 199 |
config.MacPools = make([]hcsshim.MacPool, 0) |
| 200 | 200 |
s := strings.Split(value, ",") |
| 201 | 201 |
if len(s)%2 != 0 {
|
| 202 |
- return nil, types.BadRequestErrorf("Invalid mac pool. You must specify both a start range and an end range")
|
|
| 202 |
+ return nil, types.InvalidParameterErrorf("Invalid mac pool. You must specify both a start range and an end range")
|
|
| 203 | 203 |
} |
| 204 | 204 |
for i := 0; i < len(s)-1; i += 2 {
|
| 205 | 205 |
config.MacPools = append(config.MacPools, hcsshim.MacPool{
|
| ... | ... |
@@ -242,7 +242,7 @@ func (c *networkConfiguration) processIPAM(id string, ipamV4Data, ipamV6Data []d |
| 242 | 242 |
} |
| 243 | 243 |
|
| 244 | 244 |
if len(ipamV4Data) == 0 {
|
| 245 |
- return types.BadRequestErrorf("network %s requires ipv4 configuration", id)
|
|
| 245 |
+ return types.InvalidParameterErrorf("network %s requires ipv4 configuration", id)
|
|
| 246 | 246 |
} |
| 247 | 247 |
|
| 248 | 248 |
return nil |
| ... | ... |
@@ -103,7 +103,7 @@ func (test *testEndpoint) SetMacAddress(mac net.HardwareAddr) error {
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
if mac == nil {
|
| 106 |
- return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 106 |
+ return types.InvalidParameterErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 107 | 107 |
} |
| 108 | 108 |
test.macAddress = mac.String() |
| 109 | 109 |
return nil |
| ... | ... |
@@ -111,7 +111,7 @@ func (test *testEndpoint) SetMacAddress(mac net.HardwareAddr) error {
|
| 111 | 111 |
|
| 112 | 112 |
func (test *testEndpoint) SetIPAddress(address *net.IPNet) error {
|
| 113 | 113 |
if address.IP == nil {
|
| 114 |
- return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
|
|
| 114 |
+ return types.InvalidParameterErrorf("tried to set nil IP address to endpoint interface")
|
|
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 | 117 |
test.address = address.String() |
| ... | ... |
@@ -397,7 +397,7 @@ func (ep *Endpoint) getNetworkFromStore() (*Network, error) {
|
| 397 | 397 |
// the network resources allocated for the endpoint. |
| 398 | 398 |
func (ep *Endpoint) Join(sb *Sandbox, options ...EndpointOption) error {
|
| 399 | 399 |
if sb == nil || sb.ID() == "" || sb.Key() == "" {
|
| 400 |
- return types.BadRequestErrorf("invalid Sandbox passed to endpoint join: %v", sb)
|
|
| 400 |
+ return types.InvalidParameterErrorf("invalid Sandbox passed to endpoint join: %v", sb)
|
|
| 401 | 401 |
} |
| 402 | 402 |
|
| 403 | 403 |
sb.joinLeaveStart() |
| ... | ... |
@@ -658,7 +658,7 @@ func (ep *Endpoint) hasInterface(iName string) bool {
|
| 658 | 658 |
// Leave detaches the network resources populated in the sandbox. |
| 659 | 659 |
func (ep *Endpoint) Leave(sb *Sandbox, options ...EndpointOption) error {
|
| 660 | 660 |
if sb == nil || sb.ID() == "" || sb.Key() == "" {
|
| 661 |
- return types.BadRequestErrorf("invalid Sandbox passed to endpoint leave: %v", sb)
|
|
| 661 |
+ return types.InvalidParameterErrorf("invalid Sandbox passed to endpoint leave: %v", sb)
|
|
| 662 | 662 |
} |
| 663 | 663 |
|
| 664 | 664 |
sb.joinLeaveStart() |
| ... | ... |
@@ -1112,7 +1112,7 @@ func (ep *Endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
| 1112 | 1112 |
} |
| 1113 | 1113 |
} |
| 1114 | 1114 |
if progAdd != nil {
|
| 1115 |
- return types.BadRequestErrorf("Invalid address %s: It does not belong to any of this network's subnets", prefAdd)
|
|
| 1115 |
+ return types.InvalidParameterErrorf("Invalid address %s: It does not belong to any of this network's subnets", prefAdd)
|
|
| 1116 | 1116 |
} |
| 1117 | 1117 |
return fmt.Errorf("no available IPv%d addresses on this network's address pools: %s (%s)", ipVer, n.Name(), n.ID())
|
| 1118 | 1118 |
} |
| ... | ... |
@@ -239,7 +239,7 @@ func (epi *endpointInterface) SetMacAddress(mac net.HardwareAddr) error {
|
| 239 | 239 |
return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", epi.mac, mac)
|
| 240 | 240 |
} |
| 241 | 241 |
if mac == nil {
|
| 242 |
- return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 242 |
+ return types.InvalidParameterErrorf("tried to set nil MAC address to endpoint interface")
|
|
| 243 | 243 |
} |
| 244 | 244 |
epi.mac = types.GetMacCopy(mac) |
| 245 | 245 |
return nil |
| ... | ... |
@@ -247,7 +247,7 @@ func (epi *endpointInterface) SetMacAddress(mac net.HardwareAddr) error {
|
| 247 | 247 |
|
| 248 | 248 |
func (epi *endpointInterface) SetIPAddress(address *net.IPNet) error {
|
| 249 | 249 |
if address.IP == nil {
|
| 250 |
- return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
|
|
| 250 |
+ return types.InvalidParameterErrorf("tried to set nil IP address to endpoint interface")
|
|
| 251 | 251 |
} |
| 252 | 252 |
if address.IP.To4() == nil {
|
| 253 | 253 |
return setAddress(&epi.addrv6, address) |
| ... | ... |
@@ -32,8 +32,8 @@ func (ii ErrInvalidID) Error() string {
|
| 32 | 32 |
return fmt.Sprintf("invalid id: %s", string(ii))
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
-// BadRequest denotes the type of this error |
|
| 36 |
-func (ii ErrInvalidID) BadRequest() {}
|
|
| 35 |
+// InvalidParameter denotes the type of this error |
|
| 36 |
+func (ii ErrInvalidID) InvalidParameter() {}
|
|
| 37 | 37 |
|
| 38 | 38 |
// ErrInvalidName is returned when a query-by-name or resource create method is |
| 39 | 39 |
// invoked with an empty name parameter |
| ... | ... |
@@ -43,8 +43,8 @@ func (in ErrInvalidName) Error() string {
|
| 43 | 43 |
return fmt.Sprintf("invalid name: %s", string(in))
|
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
-// BadRequest denotes the type of this error |
|
| 47 |
-func (in ErrInvalidName) BadRequest() {}
|
|
| 46 |
+// InvalidParameter denotes the type of this error |
|
| 47 |
+func (in ErrInvalidName) InvalidParameter() {}
|
|
| 48 | 48 |
|
| 49 | 49 |
// NetworkNameError is returned when a network with the same name already exists. |
| 50 | 50 |
type NetworkNameError string |
| ... | ... |
@@ -10,9 +10,9 @@ func TestErrorInterfaces(t *testing.T) {
|
| 10 | 10 |
badRequestErrorList := []error{ErrInvalidID(""), ErrInvalidName("")}
|
| 11 | 11 |
for _, err := range badRequestErrorList {
|
| 12 | 12 |
switch u := err.(type) {
|
| 13 |
- case types.BadRequestError: |
|
| 13 |
+ case types.InvalidParameterError: |
|
| 14 | 14 |
default: |
| 15 |
- t.Errorf("Failed to detect err %v is of type BadRequestError. Got type: %T", err, u)
|
|
| 15 |
+ t.Errorf("Failed to detect err %v is of type InvalidParameterError. Got type: %T", err, u)
|
|
| 16 | 16 |
} |
| 17 | 17 |
} |
| 18 | 18 |
|
| ... | ... |
@@ -119,7 +119,7 @@ func (a *Allocator) ReleasePool(poolID string) error {
|
| 119 | 119 |
log.G(context.TODO()).Debugf("ReleasePool(%s)", poolID)
|
| 120 | 120 |
k, err := PoolIDFromString(poolID) |
| 121 | 121 |
if err != nil {
|
| 122 |
- return types.BadRequestErrorf("invalid pool id: %s", poolID)
|
|
| 122 |
+ return types.InvalidParameterErrorf("invalid pool id: %s", poolID)
|
|
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 | 125 |
aSpace, err := a.getAddrSpace(k.AddressSpace) |
| ... | ... |
@@ -139,7 +139,7 @@ func (a *Allocator) getAddrSpace(as string) (*addrSpace, error) {
|
| 139 | 139 |
case globalAddressSpace: |
| 140 | 140 |
return a.global, nil |
| 141 | 141 |
} |
| 142 |
- return nil, types.BadRequestErrorf("cannot find address space %s", as)
|
|
| 142 |
+ return nil, types.InvalidParameterErrorf("cannot find address space %s", as)
|
|
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 | 145 |
func newPoolData(pool netip.Prefix) *PoolData {
|
| ... | ... |
@@ -228,7 +228,7 @@ func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s |
| 228 | 228 |
log.G(context.TODO()).Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts)
|
| 229 | 229 |
k, err := PoolIDFromString(poolID) |
| 230 | 230 |
if err != nil {
|
| 231 |
- return nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID)
|
|
| 231 |
+ return nil, nil, types.InvalidParameterErrorf("invalid pool id: %s", poolID)
|
|
| 232 | 232 |
} |
| 233 | 233 |
|
| 234 | 234 |
aSpace, err := a.getAddrSpace(k.AddressSpace) |
| ... | ... |
@@ -240,7 +240,7 @@ func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s |
| 240 | 240 |
var ok bool |
| 241 | 241 |
pref, ok = netip.AddrFromSlice(prefAddress) |
| 242 | 242 |
if !ok {
|
| 243 |
- return nil, nil, types.BadRequestErrorf("invalid preferred address: %v", prefAddress)
|
|
| 243 |
+ return nil, nil, types.InvalidParameterErrorf("invalid preferred address: %v", prefAddress)
|
|
| 244 | 244 |
} |
| 245 | 245 |
} |
| 246 | 246 |
p, err := aSpace.requestAddress(k.Subnet, k.ChildSubnet, pref.Unmap(), opts) |
| ... | ... |
@@ -288,7 +288,7 @@ func (a *Allocator) ReleaseAddress(poolID string, address net.IP) error {
|
| 288 | 288 |
log.G(context.TODO()).Debugf("ReleaseAddress(%s, %v)", poolID, address)
|
| 289 | 289 |
k, err := PoolIDFromString(poolID) |
| 290 | 290 |
if err != nil {
|
| 291 |
- return types.BadRequestErrorf("invalid pool id: %s", poolID)
|
|
| 291 |
+ return types.InvalidParameterErrorf("invalid pool id: %s", poolID)
|
|
| 292 | 292 |
} |
| 293 | 293 |
|
| 294 | 294 |
aSpace, err := a.getAddrSpace(k.AddressSpace) |
| ... | ... |
@@ -298,7 +298,7 @@ func (a *Allocator) ReleaseAddress(poolID string, address net.IP) error {
|
| 298 | 298 |
|
| 299 | 299 |
addr, ok := netip.AddrFromSlice(address) |
| 300 | 300 |
if !ok {
|
| 301 |
- return types.BadRequestErrorf("invalid address: %v", address)
|
|
| 301 |
+ return types.InvalidParameterErrorf("invalid address: %v", address)
|
|
| 302 | 302 |
} |
| 303 | 303 |
|
| 304 | 304 |
return aSpace.releaseAddress(k.Subnet, k.ChildSubnet, addr.Unmap()) |
| ... | ... |
@@ -319,7 +319,7 @@ func (aSpace *addrSpace) releaseAddress(nw, sub netip.Prefix, address netip.Addr |
| 319 | 319 |
} |
| 320 | 320 |
|
| 321 | 321 |
if !address.IsValid() {
|
| 322 |
- return types.BadRequestErrorf("invalid address")
|
|
| 322 |
+ return types.InvalidParameterErrorf("invalid address")
|
|
| 323 | 323 |
} |
| 324 | 324 |
|
| 325 | 325 |
if !nw.Contains(address) {
|
| ... | ... |
@@ -47,22 +47,22 @@ type addrSpace struct {
|
| 47 | 47 |
// reading it from the given string. |
| 48 | 48 |
func PoolIDFromString(str string) (pID PoolID, err error) {
|
| 49 | 49 |
if str == "" {
|
| 50 |
- return pID, types.BadRequestErrorf("invalid string form for subnetkey: %s", str)
|
|
| 50 |
+ return pID, types.InvalidParameterErrorf("invalid string form for subnetkey: %s", str)
|
|
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 | 53 |
p := strings.Split(str, "/") |
| 54 | 54 |
if len(p) != 3 && len(p) != 5 {
|
| 55 |
- return pID, types.BadRequestErrorf("invalid string form for subnetkey: %s", str)
|
|
| 55 |
+ return pID, types.InvalidParameterErrorf("invalid string form for subnetkey: %s", str)
|
|
| 56 | 56 |
} |
| 57 | 57 |
pID.AddressSpace = p[0] |
| 58 | 58 |
pID.Subnet, err = netip.ParsePrefix(p[1] + "/" + p[2]) |
| 59 | 59 |
if err != nil {
|
| 60 |
- return pID, types.BadRequestErrorf("%v", err)
|
|
| 60 |
+ return pID, types.InvalidParameterErrorf("invalid string form for subnetkey: %s", str)
|
|
| 61 | 61 |
} |
| 62 | 62 |
if len(p) == 5 {
|
| 63 | 63 |
pID.ChildSubnet, err = netip.ParsePrefix(p[3] + "/" + p[4]) |
| 64 | 64 |
if err != nil {
|
| 65 |
- return pID, types.BadRequestErrorf("%v", err)
|
|
| 65 |
+ return pID, types.InvalidParameterErrorf("invalid string form for subnetkey: %s", str)
|
|
| 66 | 66 |
} |
| 67 | 67 |
} |
| 68 | 68 |
|
| ... | ... |
@@ -29,15 +29,15 @@ type Registerer interface {
|
| 29 | 29 |
|
| 30 | 30 |
// Well-known errors returned by IPAM |
| 31 | 31 |
var ( |
| 32 |
- ErrInvalidAddressSpace = types.BadRequestErrorf("Invalid Address Space")
|
|
| 33 |
- ErrInvalidPool = types.BadRequestErrorf("Invalid Address Pool")
|
|
| 34 |
- ErrInvalidSubPool = types.BadRequestErrorf("Invalid Address SubPool")
|
|
| 32 |
+ ErrInvalidAddressSpace = types.InvalidParameterErrorf("Invalid Address Space")
|
|
| 33 |
+ ErrInvalidPool = types.InvalidParameterErrorf("Invalid Address Pool")
|
|
| 34 |
+ ErrInvalidSubPool = types.InvalidParameterErrorf("Invalid Address SubPool")
|
|
| 35 | 35 |
ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool")
|
| 36 | 36 |
ErrNoIPReturned = types.NoServiceErrorf("No address returned")
|
| 37 | 37 |
ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
|
| 38 |
- ErrIPOutOfRange = types.BadRequestErrorf("Requested address is out of range")
|
|
| 38 |
+ ErrIPOutOfRange = types.InvalidParameterErrorf("Requested address is out of range")
|
|
| 39 | 39 |
ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
|
| 40 |
- ErrBadPool = types.BadRequestErrorf("Address space does not contain specified address pool")
|
|
| 40 |
+ ErrBadPool = types.InvalidParameterErrorf("Address space does not contain specified address pool")
|
|
| 41 | 41 |
) |
| 42 | 42 |
|
| 43 | 43 |
// Ipam represents the interface the IPAM service plugins must implement |
| ... | ... |
@@ -25,16 +25,16 @@ func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
|
| 25 | 25 |
|
| 26 | 26 |
func (a *allocator) RequestPool(addressSpace, requestedPool, requestedSubPool string, _ map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
|
| 27 | 27 |
if addressSpace != defaultAddressSpace {
|
| 28 |
- return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
|
|
| 28 |
+ return "", nil, nil, types.InvalidParameterErrorf("unknown address space: %s", addressSpace)
|
|
| 29 | 29 |
} |
| 30 | 30 |
if requestedPool != "" {
|
| 31 |
- return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address pool requests")
|
|
| 31 |
+ return "", nil, nil, types.InvalidParameterErrorf("null ipam driver does not handle specific address pool requests")
|
|
| 32 | 32 |
} |
| 33 | 33 |
if requestedSubPool != "" {
|
| 34 |
- return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address subpool requests")
|
|
| 34 |
+ return "", nil, nil, types.InvalidParameterErrorf("null ipam driver does not handle specific address subpool requests")
|
|
| 35 | 35 |
} |
| 36 | 36 |
if v6 {
|
| 37 |
- return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle IPv6 address pool pool requests")
|
|
| 37 |
+ return "", nil, nil, types.InvalidParameterErrorf("null ipam driver does not handle IPv6 address pool pool requests")
|
|
| 38 | 38 |
} |
| 39 | 39 |
return defaultPoolID, defaultPool, nil, nil |
| 40 | 40 |
} |
| ... | ... |
@@ -45,14 +45,14 @@ func (a *allocator) ReleasePool(poolID string) error {
|
| 45 | 45 |
|
| 46 | 46 |
func (a *allocator) RequestAddress(poolID string, ip net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) {
|
| 47 | 47 |
if poolID != defaultPoolID {
|
| 48 |
- return nil, nil, types.BadRequestErrorf("unknown pool id: %s", poolID)
|
|
| 48 |
+ return nil, nil, types.InvalidParameterErrorf("unknown pool id: %s", poolID)
|
|
| 49 | 49 |
} |
| 50 | 50 |
return nil, nil, nil |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 | 53 |
func (a *allocator) ReleaseAddress(poolID string, ip net.IP) error {
|
| 54 | 54 |
if poolID != defaultPoolID {
|
| 55 |
- return types.BadRequestErrorf("unknown pool id: %s", poolID)
|
|
| 55 |
+ return types.InvalidParameterErrorf("unknown pool id: %s", poolID)
|
|
| 56 | 56 |
} |
| 57 | 57 |
return nil |
| 58 | 58 |
} |
| ... | ... |
@@ -1091,7 +1091,7 @@ func TestContainerInvalidLeave(t *testing.T) {
|
| 1091 | 1091 |
if err = ep.Leave(nil); err == nil {
|
| 1092 | 1092 |
t.Fatalf("Expected to fail leave nil Sandbox")
|
| 1093 | 1093 |
} |
| 1094 |
- if _, ok := err.(types.BadRequestError); !ok {
|
|
| 1094 |
+ if _, ok := err.(types.InvalidParameterError); !ok {
|
|
| 1095 | 1095 |
t.Fatalf("Unexpected error type returned: %T. Desc: %s", err, err.Error())
|
| 1096 | 1096 |
} |
| 1097 | 1097 |
|
| ... | ... |
@@ -1099,7 +1099,7 @@ func TestContainerInvalidLeave(t *testing.T) {
|
| 1099 | 1099 |
if err = ep.Leave(fsbx); err == nil {
|
| 1100 | 1100 |
t.Fatalf("Expected to fail leave with invalid Sandbox")
|
| 1101 | 1101 |
} |
| 1102 |
- if _, ok := err.(types.BadRequestError); !ok {
|
|
| 1102 |
+ if _, ok := err.(types.InvalidParameterError); !ok {
|
|
| 1103 | 1103 |
t.Fatalf("Unexpected error type returned: %T. Desc: %s", err, err.Error())
|
| 1104 | 1104 |
} |
| 1105 | 1105 |
} |
| ... | ... |
@@ -1516,7 +1516,7 @@ func TestEndpointJoin(t *testing.T) {
|
| 1516 | 1516 |
if err == nil {
|
| 1517 | 1517 |
t.Fatalf("Expected to fail join with nil Sandbox")
|
| 1518 | 1518 |
} |
| 1519 |
- if _, ok := err.(types.BadRequestError); !ok {
|
|
| 1519 |
+ if _, ok := err.(types.InvalidParameterError); !ok {
|
|
| 1520 | 1520 |
t.Fatalf("Unexpected error type returned: %T", err)
|
| 1521 | 1521 |
} |
| 1522 | 1522 |
|
| ... | ... |
@@ -1524,7 +1524,7 @@ func TestEndpointJoin(t *testing.T) {
|
| 1524 | 1524 |
if err = ep1.Join(fsbx); err == nil {
|
| 1525 | 1525 |
t.Fatalf("Expected to fail join with invalid Sandbox")
|
| 1526 | 1526 |
} |
| 1527 |
- if _, ok := err.(types.BadRequestError); !ok {
|
|
| 1527 |
+ if _, ok := err.(types.InvalidParameterError); !ok {
|
|
| 1528 | 1528 |
t.Fatalf("Unexpected error type returned: %T", err)
|
| 1529 | 1529 |
} |
| 1530 | 1530 |
|
| ... | ... |
@@ -87,7 +87,7 @@ type IpamConf struct {
|
| 87 | 87 |
// Validate checks whether the configuration is valid |
| 88 | 88 |
func (c *IpamConf) Validate() error {
|
| 89 | 89 |
if c.Gateway != "" && nil == net.ParseIP(c.Gateway) {
|
| 90 |
- return types.BadRequestErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
|
|
| 90 |
+ return types.InvalidParameterErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
|
|
| 91 | 91 |
} |
| 92 | 92 |
return nil |
| 93 | 93 |
} |
| ... | ... |
@@ -1136,7 +1136,7 @@ func (n *Network) createEndpoint(name string, options ...EndpointOption) (*Endpo |
| 1136 | 1136 |
|
| 1137 | 1137 |
for _, llIPNet := range ep.Iface().LinkLocalAddresses() {
|
| 1138 | 1138 |
if !llIPNet.IP.IsLinkLocalUnicast() {
|
| 1139 |
- return nil, types.BadRequestErrorf("invalid link local IP address: %v", llIPNet.IP)
|
|
| 1139 |
+ return nil, types.InvalidParameterErrorf("invalid link local IP address: %v", llIPNet.IP)
|
|
| 1140 | 1140 |
} |
| 1141 | 1141 |
} |
| 1142 | 1142 |
|
| ... | ... |
@@ -1602,7 +1602,7 @@ func (n *Network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
| 1602 | 1602 |
|
| 1603 | 1603 |
if gws, ok := d.Meta[netlabel.Gateway]; ok {
|
| 1604 | 1604 |
if d.Gateway, err = types.ParseCIDR(gws); err != nil {
|
| 1605 |
- return types.BadRequestErrorf("failed to parse gateway address (%v) returned by ipam driver: %v", gws, err)
|
|
| 1605 |
+ return types.InvalidParameterErrorf("failed to parse gateway address (%v) returned by ipam driver: %v", gws, err)
|
|
| 1606 | 1606 |
} |
| 1607 | 1607 |
} |
| 1608 | 1608 |
|
| ... | ... |
@@ -1625,7 +1625,7 @@ func (n *Network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
| 1625 | 1625 |
d.IPAMData.AuxAddresses = make(map[string]*net.IPNet, len(cfg.AuxAddresses)) |
| 1626 | 1626 |
for k, v := range cfg.AuxAddresses {
|
| 1627 | 1627 |
if ip = net.ParseIP(v); ip == nil {
|
| 1628 |
- return types.BadRequestErrorf("non parsable secondary ip address (%s:%s) passed for network %s", k, v, n.Name())
|
|
| 1628 |
+ return types.InvalidParameterErrorf("non parsable secondary ip address (%s:%s) passed for network %s", k, v, n.Name())
|
|
| 1629 | 1629 |
} |
| 1630 | 1630 |
if !d.Pool.Contains(ip) {
|
| 1631 | 1631 |
return types.ForbiddenErrorf("auxiliary address: (%s:%s) must belong to the master pool: %s", k, v, d.Pool)
|
| ... | ... |
@@ -169,7 +169,7 @@ func (c *Controller) processExternalKey(conn net.Conn) error {
|
| 169 | 169 |
search := SandboxContainerWalker(&sandbox, s.ContainerID) |
| 170 | 170 |
c.WalkSandboxes(search) |
| 171 | 171 |
if sandbox == nil {
|
| 172 |
- return types.BadRequestErrorf("no sandbox present for %s", s.ContainerID)
|
|
| 172 |
+ return types.InvalidParameterErrorf("no sandbox present for %s", s.ContainerID)
|
|
| 173 | 173 |
} |
| 174 | 174 |
|
| 175 | 175 |
return sandbox.SetKey(s.Key) |
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"strconv" |
| 9 | 9 |
"strings" |
| 10 | 10 |
|
| 11 |
+ "github.com/docker/docker/errdefs" |
|
| 11 | 12 |
"github.com/ishidawataru/sctp" |
| 12 | 13 |
) |
| 13 | 14 |
|
| ... | ... |
@@ -355,10 +356,10 @@ type MaskableError interface {
|
| 355 | 355 |
Maskable() |
| 356 | 356 |
} |
| 357 | 357 |
|
| 358 |
-// BadRequestError is an interface for errors originated by a bad request |
|
| 359 |
-type BadRequestError interface {
|
|
| 360 |
- // BadRequest makes implementer into BadRequestError type |
|
| 361 |
- BadRequest() |
|
| 358 |
+// InvalidParameterError is an interface for errors originated by a bad request |
|
| 359 |
+type InvalidParameterError interface {
|
|
| 360 |
+ // InvalidParameter makes implementer into InvalidParameterError type |
|
| 361 |
+ InvalidParameter() |
|
| 362 | 362 |
} |
| 363 | 363 |
|
| 364 | 364 |
// NotFoundError is an interface for errors raised because a needed resource is not available |
| ... | ... |
@@ -395,9 +396,9 @@ type InternalError interface {
|
| 395 | 395 |
* Well-known Error Formatters |
| 396 | 396 |
******************************/ |
| 397 | 397 |
|
| 398 |
-// BadRequestErrorf creates an instance of BadRequestError |
|
| 399 |
-func BadRequestErrorf(format string, params ...interface{}) error {
|
|
| 400 |
- return badRequest(fmt.Sprintf(format, params...)) |
|
| 398 |
+// InvalidParameterErrorf creates an instance of InvalidParameterError |
|
| 399 |
+func InvalidParameterErrorf(format string, params ...interface{}) error {
|
|
| 400 |
+ return errdefs.InvalidParameter(fmt.Errorf(format, params...)) |
|
| 401 | 401 |
} |
| 402 | 402 |
|
| 403 | 403 |
// NotFoundErrorf creates an instance of NotFoundError |
| ... | ... |
@@ -433,13 +434,6 @@ func InternalMaskableErrorf(format string, params ...interface{}) error {
|
| 433 | 433 |
/*********************** |
| 434 | 434 |
* Internal Error Types |
| 435 | 435 |
***********************/ |
| 436 |
-type badRequest string |
|
| 437 |
- |
|
| 438 |
-func (br badRequest) Error() string {
|
|
| 439 |
- return string(br) |
|
| 440 |
-} |
|
| 441 |
-func (br badRequest) BadRequest() {}
|
|
| 442 |
- |
|
| 443 | 436 |
type notFound string |
| 444 | 437 |
|
| 445 | 438 |
func (nf notFound) Error() string {
|
| ... | ... |
@@ -8,11 +8,11 @@ import ( |
| 8 | 8 |
func TestErrorConstructors(t *testing.T) {
|
| 9 | 9 |
var err error |
| 10 | 10 |
|
| 11 |
- err = BadRequestErrorf("Io ho %d uccello", 1)
|
|
| 11 |
+ err = InvalidParameterErrorf("Io ho %d uccello", 1)
|
|
| 12 | 12 |
if err.Error() != "Io ho 1 uccello" {
|
| 13 | 13 |
t.Fatal(err) |
| 14 | 14 |
} |
| 15 |
- if _, ok := err.(BadRequestError); !ok {
|
|
| 15 |
+ if _, ok := err.(InvalidParameterError); !ok {
|
|
| 16 | 16 |
t.Fatal(err) |
| 17 | 17 |
} |
| 18 | 18 |
if _, ok := err.(MaskableError); ok {
|