error.go 5.5 KB

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