errors.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package bridge
  2. import "fmt"
  3. // ErrInvalidEndpointConfig error is returned when an endpoint create is attempted with an invalid endpoint configuration.
  4. type ErrInvalidEndpointConfig struct{}
  5. func (eiec *ErrInvalidEndpointConfig) Error() string {
  6. return "trying to create an endpoint with an invalid endpoint configuration"
  7. }
  8. // BadRequest denotes the type of this error
  9. func (eiec *ErrInvalidEndpointConfig) BadRequest() {}
  10. // ErrNoIPAddr error is returned when bridge has no IPv4 address configured.
  11. type ErrNoIPAddr struct{}
  12. func (enip *ErrNoIPAddr) Error() string {
  13. return "bridge has no IPv4 address configured"
  14. }
  15. // InternalError denotes the type of this error
  16. func (enip *ErrNoIPAddr) InternalError() {}
  17. // ErrInvalidGateway is returned when the user provided default gateway (v4/v6) is not not valid.
  18. type ErrInvalidGateway struct{}
  19. func (eig *ErrInvalidGateway) Error() string {
  20. return "default gateway ip must be part of the network"
  21. }
  22. // BadRequest denotes the type of this error
  23. func (eig *ErrInvalidGateway) BadRequest() {}
  24. // ErrInvalidMtu is returned when the user provided MTU is not valid.
  25. type ErrInvalidMtu int
  26. func (eim ErrInvalidMtu) Error() string {
  27. return fmt.Sprintf("invalid MTU number: %d", int(eim))
  28. }
  29. // BadRequest denotes the type of this error
  30. func (eim ErrInvalidMtu) BadRequest() {}
  31. // ErrUnsupportedAddressType is returned when the specified address type is not supported.
  32. type ErrUnsupportedAddressType string
  33. func (uat ErrUnsupportedAddressType) Error() string {
  34. return fmt.Sprintf("unsupported address type: %s", string(uat))
  35. }
  36. // BadRequest denotes the type of this error
  37. func (uat ErrUnsupportedAddressType) BadRequest() {}
  38. // ActiveEndpointsError is returned when there are
  39. // still active endpoints in the network being deleted.
  40. type ActiveEndpointsError string
  41. func (aee ActiveEndpointsError) Error() string {
  42. return fmt.Sprintf("network %s has active endpoint", string(aee))
  43. }
  44. // Forbidden denotes the type of this error
  45. func (aee ActiveEndpointsError) Forbidden() {}
  46. // InvalidNetworkIDError is returned when the passed
  47. // network id for an existing network is not a known id.
  48. type InvalidNetworkIDError string
  49. func (inie InvalidNetworkIDError) Error() string {
  50. return fmt.Sprintf("invalid network id %s", string(inie))
  51. }
  52. // NotFound denotes the type of this error
  53. func (inie InvalidNetworkIDError) NotFound() {}
  54. // InvalidEndpointIDError is returned when the passed
  55. // endpoint id is not valid.
  56. type InvalidEndpointIDError string
  57. func (ieie InvalidEndpointIDError) Error() string {
  58. return fmt.Sprintf("invalid endpoint id: %s", string(ieie))
  59. }
  60. // BadRequest denotes the type of this error
  61. func (ieie InvalidEndpointIDError) BadRequest() {}
  62. // EndpointNotFoundError is returned when the no endpoint
  63. // with the passed endpoint id is found.
  64. type EndpointNotFoundError string
  65. func (enfe EndpointNotFoundError) Error() string {
  66. return fmt.Sprintf("endpoint not found: %s", string(enfe))
  67. }
  68. // NotFound denotes the type of this error
  69. func (enfe EndpointNotFoundError) NotFound() {}
  70. // NonDefaultBridgeExistError is returned when a non-default
  71. // bridge config is passed but it does not already exist.
  72. type NonDefaultBridgeExistError string
  73. func (ndbee NonDefaultBridgeExistError) Error() string {
  74. return fmt.Sprintf("bridge device with non default name %s must be created manually", string(ndbee))
  75. }
  76. // Forbidden denotes the type of this error
  77. func (ndbee NonDefaultBridgeExistError) Forbidden() {}
  78. // NonDefaultBridgeNeedsIPError is returned when a non-default
  79. // bridge config is passed but it has no ip configured
  80. type NonDefaultBridgeNeedsIPError string
  81. func (ndbee NonDefaultBridgeNeedsIPError) Error() string {
  82. return fmt.Sprintf("bridge device with non default name %s must have a valid IP address", string(ndbee))
  83. }
  84. // Forbidden denotes the type of this error
  85. func (ndbee NonDefaultBridgeNeedsIPError) Forbidden() {}