error.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package libnetwork
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. // ErrNoSuchNetwork is returned when a network query finds no result
  7. type ErrNoSuchNetwork string
  8. func (nsn ErrNoSuchNetwork) Error() string {
  9. return fmt.Sprintf("network %s not found", string(nsn))
  10. }
  11. // NotFound denotes the type of this error
  12. func (nsn ErrNoSuchNetwork) NotFound() {}
  13. // ErrNoSuchEndpoint is returned when an endpoint query finds no result
  14. type ErrNoSuchEndpoint string
  15. func (nse ErrNoSuchEndpoint) Error() string {
  16. return fmt.Sprintf("endpoint %s not found", string(nse))
  17. }
  18. // NotFound denotes the type of this error
  19. func (nse ErrNoSuchEndpoint) NotFound() {}
  20. // ErrInvalidID is returned when a query-by-id method is being invoked
  21. // with an empty id parameter
  22. type ErrInvalidID string
  23. func (ii ErrInvalidID) Error() string {
  24. return fmt.Sprintf("invalid id: %s", string(ii))
  25. }
  26. // BadRequest denotes the type of this error
  27. func (ii ErrInvalidID) BadRequest() {}
  28. // ErrInvalidName is returned when a query-by-name or resource create method is
  29. // invoked with an empty name parameter
  30. type ErrInvalidName string
  31. func (in ErrInvalidName) Error() string {
  32. return fmt.Sprintf("invalid name: %s", string(in))
  33. }
  34. // BadRequest denotes the type of this error
  35. func (in ErrInvalidName) BadRequest() {}
  36. // NetworkNameError is returned when a network with the same name already exists.
  37. type NetworkNameError string
  38. func (nnr NetworkNameError) Error() string {
  39. return fmt.Sprintf("network with name %s already exists", string(nnr))
  40. }
  41. // Forbidden denotes the type of this error
  42. func (nnr NetworkNameError) Forbidden() {}
  43. // UnknownNetworkError is returned when libnetwork could not find in its database
  44. // a network with the same name and id.
  45. type UnknownNetworkError struct {
  46. name string
  47. id string
  48. }
  49. func (une *UnknownNetworkError) Error() string {
  50. return fmt.Sprintf("unknown network %s id %s", une.name, une.id)
  51. }
  52. // NotFound denotes the type of this error
  53. func (une *UnknownNetworkError) NotFound() {}
  54. // ActiveEndpointsError is returned when a network is deleted which has active
  55. // endpoints in it.
  56. type ActiveEndpointsError struct {
  57. name string
  58. id string
  59. }
  60. func (aee *ActiveEndpointsError) Error() string {
  61. return fmt.Sprintf("network %s id %s has active endpoints", aee.name, aee.id)
  62. }
  63. // Forbidden denotes the type of this error
  64. func (aee *ActiveEndpointsError) Forbidden() {}
  65. // UnknownEndpointError is returned when libnetwork could not find in its database
  66. // an endpoint with the same name and id.
  67. type UnknownEndpointError struct {
  68. name string
  69. id string
  70. }
  71. func (uee *UnknownEndpointError) Error() string {
  72. return fmt.Sprintf("unknown endpoint %s id %s", uee.name, uee.id)
  73. }
  74. // NotFound denotes the type of this error
  75. func (uee *UnknownEndpointError) NotFound() {}
  76. // ActiveContainerError is returned when an endpoint is deleted which has active
  77. // containers attached to it.
  78. type ActiveContainerError struct {
  79. name string
  80. id string
  81. }
  82. func (ace *ActiveContainerError) Error() string {
  83. return fmt.Sprintf("endpoint with name %s id %s has active containers", ace.name, ace.id)
  84. }
  85. // Forbidden denotes the type of this error
  86. func (ace *ActiveContainerError) Forbidden() {}
  87. // InvalidContainerIDError is returned when an invalid container id is passed
  88. // in Join/Leave
  89. type InvalidContainerIDError string
  90. func (id InvalidContainerIDError) Error() string {
  91. return fmt.Sprintf("invalid container id %s", string(id))
  92. }
  93. // BadRequest denotes the type of this error
  94. func (id InvalidContainerIDError) BadRequest() {}
  95. // ManagerRedirectError is returned when the request should be redirected to Manager
  96. type ManagerRedirectError string
  97. func (mr ManagerRedirectError) Error() string {
  98. return "Redirect the request to the manager"
  99. }
  100. // Maskable denotes the type of this error
  101. func (mr ManagerRedirectError) Maskable() {}
  102. // ErrDataStoreNotInitialized is returned if an invalid data scope is passed
  103. // for getting data store
  104. var ErrDataStoreNotInitialized = errors.New("datastore is not initialized")