error.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // ErrInvalidNetworkDriver is returned if an invalid driver
  21. // name is passed.
  22. type ErrInvalidNetworkDriver string
  23. func (ind ErrInvalidNetworkDriver) Error() string {
  24. return fmt.Sprintf("invalid driver bound to network: %s", string(ind))
  25. }
  26. // BadRequest denotes the type of this error
  27. func (ind ErrInvalidNetworkDriver) BadRequest() {}
  28. // ErrInvalidJoin is returned if a join is attempted on an endpoint
  29. // which already has a container joined.
  30. type ErrInvalidJoin struct{}
  31. func (ij ErrInvalidJoin) Error() string {
  32. return "a container has already joined the endpoint"
  33. }
  34. // BadRequest denotes the type of this error
  35. func (ij ErrInvalidJoin) BadRequest() {}
  36. // ErrNoContainer is returned when the endpoint has no container
  37. // attached to it.
  38. type ErrNoContainer struct{}
  39. func (nc ErrNoContainer) Error() string {
  40. return "no container is attached to the endpoint"
  41. }
  42. // Maskable denotes the type of this error
  43. func (nc ErrNoContainer) Maskable() {}
  44. // ErrInvalidID is returned when a query-by-id method is being invoked
  45. // with an empty id parameter
  46. type ErrInvalidID string
  47. func (ii ErrInvalidID) Error() string {
  48. return fmt.Sprintf("invalid id: %s", string(ii))
  49. }
  50. // BadRequest denotes the type of this error
  51. func (ii ErrInvalidID) BadRequest() {}
  52. // ErrInvalidName is returned when a query-by-name or resource create method is
  53. // invoked with an empty name parameter
  54. type ErrInvalidName string
  55. func (in ErrInvalidName) Error() string {
  56. return fmt.Sprintf("invalid name: %s", string(in))
  57. }
  58. // BadRequest denotes the type of this error
  59. func (in ErrInvalidName) BadRequest() {}
  60. // ErrInvalidConfigFile type is returned when an invalid LibNetwork config file is detected
  61. type ErrInvalidConfigFile string
  62. func (cf ErrInvalidConfigFile) Error() string {
  63. return fmt.Sprintf("Invalid Config file %q", string(cf))
  64. }
  65. // NetworkTypeError type is returned when the network type string is not
  66. // known to libnetwork.
  67. type NetworkTypeError string
  68. func (nt NetworkTypeError) Error() string {
  69. return fmt.Sprintf("unknown driver %q", string(nt))
  70. }
  71. // NotFound denotes the type of this error
  72. func (nt NetworkTypeError) NotFound() {}
  73. // NetworkNameError is returned when a network with the same name already exists.
  74. type NetworkNameError string
  75. func (nnr NetworkNameError) Error() string {
  76. return fmt.Sprintf("network with name %s already exists", string(nnr))
  77. }
  78. // Forbidden denotes the type of this error
  79. func (nnr NetworkNameError) Forbidden() {}
  80. // UnknownNetworkError is returned when libnetwork could not find in its database
  81. // a network with the same name and id.
  82. type UnknownNetworkError struct {
  83. name string
  84. id string
  85. }
  86. func (une *UnknownNetworkError) Error() string {
  87. return fmt.Sprintf("unknown network %s id %s", une.name, une.id)
  88. }
  89. // NotFound denotes the type of this error
  90. func (une *UnknownNetworkError) NotFound() {}
  91. // ActiveEndpointsError is returned when a network is deleted which has active
  92. // endpoints in it.
  93. type ActiveEndpointsError struct {
  94. name string
  95. id string
  96. }
  97. func (aee *ActiveEndpointsError) Error() string {
  98. return fmt.Sprintf("network %s id %s has active endpoints", aee.name, aee.id)
  99. }
  100. // Forbidden denotes the type of this error
  101. func (aee *ActiveEndpointsError) Forbidden() {}
  102. // UnknownEndpointError is returned when libnetwork could not find in its database
  103. // an endpoint with the same name and id.
  104. type UnknownEndpointError struct {
  105. name string
  106. id string
  107. }
  108. func (uee *UnknownEndpointError) Error() string {
  109. return fmt.Sprintf("unknown endpoint %s id %s", uee.name, uee.id)
  110. }
  111. // NotFound denotes the type of this error
  112. func (uee *UnknownEndpointError) NotFound() {}
  113. // ActiveContainerError is returned when an endpoint is deleted which has active
  114. // containers attached to it.
  115. type ActiveContainerError struct {
  116. name string
  117. id string
  118. }
  119. func (ace *ActiveContainerError) Error() string {
  120. return fmt.Sprintf("endpoint with name %s id %s has active containers", ace.name, ace.id)
  121. }
  122. // Forbidden denotes the type of this error
  123. func (ace *ActiveContainerError) Forbidden() {}
  124. // InvalidContainerIDError is returned when an invalid container id is passed
  125. // in Join/Leave
  126. type InvalidContainerIDError string
  127. func (id InvalidContainerIDError) Error() string {
  128. return fmt.Sprintf("invalid container id %s", string(id))
  129. }
  130. // BadRequest denotes the type of this error
  131. func (id InvalidContainerIDError) BadRequest() {}
  132. // ManagerRedirectError is returned when the request should be redirected to Manager
  133. type ManagerRedirectError string
  134. func (mr ManagerRedirectError) Error() string {
  135. return "Redirect the request to the manager"
  136. }
  137. // Maskable denotes the type of this error
  138. func (mr ManagerRedirectError) Maskable() {}
  139. // ErrDataStoreNotInitialized is returned if an invalid data scope is passed
  140. // for getting data store
  141. var ErrDataStoreNotInitialized = errors.New("datastore is not initialized")