error.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package libnetwork
  2. import (
  3. "fmt"
  4. )
  5. // ErrNoSuchNetwork is returned when a network query finds no result
  6. type ErrNoSuchNetwork string
  7. func (nsn ErrNoSuchNetwork) Error() string {
  8. return fmt.Sprintf("network %s not found", string(nsn))
  9. }
  10. // NotFound denotes the type of this error
  11. func (nsn ErrNoSuchNetwork) NotFound() {}
  12. // ErrNoSuchEndpoint is returned when an endpoint query finds no result
  13. type ErrNoSuchEndpoint string
  14. func (nse ErrNoSuchEndpoint) Error() string {
  15. return fmt.Sprintf("endpoint %s not found", string(nse))
  16. }
  17. // NotFound denotes the type of this error
  18. func (nse ErrNoSuchEndpoint) NotFound() {}
  19. // ErrInvalidID is returned when a query-by-id method is being invoked
  20. // with an empty id parameter
  21. type ErrInvalidID string
  22. func (ii ErrInvalidID) Error() string {
  23. return fmt.Sprintf("invalid id: %s", string(ii))
  24. }
  25. // InvalidParameter denotes the type of this error
  26. func (ii ErrInvalidID) InvalidParameter() {}
  27. // ErrInvalidName is returned when a query-by-name or resource create method is
  28. // invoked with an empty name parameter
  29. type ErrInvalidName string
  30. func (in ErrInvalidName) Error() string {
  31. return fmt.Sprintf("invalid name: %s", string(in))
  32. }
  33. // InvalidParameter denotes the type of this error
  34. func (in ErrInvalidName) InvalidParameter() {}
  35. // NetworkNameError is returned when a network with the same name already exists.
  36. type NetworkNameError string
  37. func (nnr NetworkNameError) Error() string {
  38. return fmt.Sprintf("network with name %s already exists", string(nnr))
  39. }
  40. // Conflict denotes the type of this error
  41. func (nnr NetworkNameError) Conflict() {}
  42. // UnknownNetworkError is returned when libnetwork could not find in its database
  43. // a network with the same name and id.
  44. type UnknownNetworkError struct {
  45. name string
  46. id string
  47. }
  48. func (une *UnknownNetworkError) Error() string {
  49. return fmt.Sprintf("unknown network %s id %s", une.name, une.id)
  50. }
  51. // NotFound denotes the type of this error
  52. func (une *UnknownNetworkError) NotFound() {}
  53. // ActiveEndpointsError is returned when a network is deleted which has active
  54. // endpoints in it.
  55. type ActiveEndpointsError struct {
  56. name string
  57. id string
  58. }
  59. func (aee *ActiveEndpointsError) Error() string {
  60. return fmt.Sprintf("network %s id %s has active endpoints", aee.name, aee.id)
  61. }
  62. // Forbidden denotes the type of this error
  63. func (aee *ActiveEndpointsError) Forbidden() {}
  64. // ActiveContainerError is returned when an endpoint is deleted which has active
  65. // containers attached to it.
  66. type ActiveContainerError struct {
  67. name string
  68. id string
  69. }
  70. func (ace *ActiveContainerError) Error() string {
  71. return fmt.Sprintf("endpoint with name %s id %s has active containers", ace.name, ace.id)
  72. }
  73. // Forbidden denotes the type of this error
  74. func (ace *ActiveContainerError) Forbidden() {}
  75. // ManagerRedirectError is returned when the request should be redirected to Manager
  76. type ManagerRedirectError string
  77. func (mr ManagerRedirectError) Error() string {
  78. return "Redirect the request to the manager"
  79. }
  80. // Maskable denotes the type of this error
  81. func (mr ManagerRedirectError) Maskable() {}