error.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // BadRequest denotes the type of this error
  11. func (nsn ErrNoSuchNetwork) BadRequest() {}
  12. // ErrNoSuchEndpoint is returned when a 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. // BadRequest denotes the type of this error
  18. func (nse ErrNoSuchEndpoint) BadRequest() {}
  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 "a container has already joined 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. // NetworkTypeError type is returned when the network type string is not
  60. // known to libnetwork.
  61. type NetworkTypeError string
  62. func (nt NetworkTypeError) Error() string {
  63. return fmt.Sprintf("unknown driver %q", string(nt))
  64. }
  65. // NotFound denotes the type of this error
  66. func (nt NetworkTypeError) NotFound() {}
  67. // NetworkNameError is returned when a network with the same name already exists.
  68. type NetworkNameError string
  69. func (nnr NetworkNameError) Error() string {
  70. return fmt.Sprintf("network with name %s already exists", string(nnr))
  71. }
  72. // Forbidden denotes the type of this error
  73. func (nnr NetworkNameError) Forbidden() {}
  74. // UnknownNetworkError is returned when libnetwork could not find in it's database
  75. // a network with the same name and id.
  76. type UnknownNetworkError struct {
  77. name string
  78. id string
  79. }
  80. func (une *UnknownNetworkError) Error() string {
  81. return fmt.Sprintf("unknown network %s id %s", une.name, une.id)
  82. }
  83. // NotFound denotes the type of this error
  84. func (une *UnknownNetworkError) NotFound() {}
  85. // ActiveEndpointsError is returned when a network is deleted which has active
  86. // endpoints in it.
  87. type ActiveEndpointsError struct {
  88. name string
  89. id string
  90. }
  91. func (aee *ActiveEndpointsError) Error() string {
  92. return fmt.Sprintf("network with name %s id %s has active endpoints", aee.name, aee.id)
  93. }
  94. // Forbidden denotes the type of this error
  95. func (aee *ActiveEndpointsError) Forbidden() {}
  96. // UnknownEndpointError is returned when libnetwork could not find in it's database
  97. // an endpoint with the same name and id.
  98. type UnknownEndpointError struct {
  99. name string
  100. id string
  101. }
  102. func (uee *UnknownEndpointError) Error() string {
  103. return fmt.Sprintf("unknown endpoint %s id %s", uee.name, uee.id)
  104. }
  105. // NotFound denotes the type of this error
  106. func (uee *UnknownEndpointError) NotFound() {}
  107. // ActiveContainerError is returned when an endpoint is deleted which has active
  108. // containers attached to it.
  109. type ActiveContainerError struct {
  110. name string
  111. id string
  112. }
  113. func (ace *ActiveContainerError) Error() string {
  114. return fmt.Sprintf("endpoint with name %s id %s has active containers", ace.name, ace.id)
  115. }
  116. // Forbidden denotes the type of this error
  117. func (ace *ActiveContainerError) Forbidden() {}
  118. // InvalidContainerIDError is returned when an invalid container id is passed
  119. // in Join/Leave
  120. type InvalidContainerIDError string
  121. func (id InvalidContainerIDError) Error() string {
  122. return fmt.Sprintf("invalid container id %s", string(id))
  123. }
  124. // BadRequest denotes the type of this error
  125. func (id InvalidContainerIDError) BadRequest() {}