codes.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. *
  3. * Copyright 2014, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. // Package codes defines the canonical error codes used by gRPC. It is
  34. // consistent across various languages.
  35. package codes // import "google.golang.org/grpc/codes"
  36. // A Code is an unsigned 32-bit error code as defined in the gRPC spec.
  37. type Code uint32
  38. //go:generate stringer -type=Code
  39. const (
  40. // OK is returned on success.
  41. OK Code = 0
  42. // Canceled indicates the operation was cancelled (typically by the caller).
  43. Canceled Code = 1
  44. // Unknown error. An example of where this error may be returned is
  45. // if a Status value received from another address space belongs to
  46. // an error-space that is not known in this address space. Also
  47. // errors raised by APIs that do not return enough error information
  48. // may be converted to this error.
  49. Unknown Code = 2
  50. // InvalidArgument indicates client specified an invalid argument.
  51. // Note that this differs from FailedPrecondition. It indicates arguments
  52. // that are problematic regardless of the state of the system
  53. // (e.g., a malformed file name).
  54. InvalidArgument Code = 3
  55. // DeadlineExceeded means operation expired before completion.
  56. // For operations that change the state of the system, this error may be
  57. // returned even if the operation has completed successfully. For
  58. // example, a successful response from a server could have been delayed
  59. // long enough for the deadline to expire.
  60. DeadlineExceeded Code = 4
  61. // NotFound means some requested entity (e.g., file or directory) was
  62. // not found.
  63. NotFound Code = 5
  64. // AlreadyExists means an attempt to create an entity failed because one
  65. // already exists.
  66. AlreadyExists Code = 6
  67. // PermissionDenied indicates the caller does not have permission to
  68. // execute the specified operation. It must not be used for rejections
  69. // caused by exhausting some resource (use ResourceExhausted
  70. // instead for those errors). It must not be
  71. // used if the caller cannot be identified (use Unauthenticated
  72. // instead for those errors).
  73. PermissionDenied Code = 7
  74. // Unauthenticated indicates the request does not have valid
  75. // authentication credentials for the operation.
  76. Unauthenticated Code = 16
  77. // ResourceExhausted indicates some resource has been exhausted, perhaps
  78. // a per-user quota, or perhaps the entire file system is out of space.
  79. ResourceExhausted Code = 8
  80. // FailedPrecondition indicates operation was rejected because the
  81. // system is not in a state required for the operation's execution.
  82. // For example, directory to be deleted may be non-empty, an rmdir
  83. // operation is applied to a non-directory, etc.
  84. //
  85. // A litmus test that may help a service implementor in deciding
  86. // between FailedPrecondition, Aborted, and Unavailable:
  87. // (a) Use Unavailable if the client can retry just the failing call.
  88. // (b) Use Aborted if the client should retry at a higher-level
  89. // (e.g., restarting a read-modify-write sequence).
  90. // (c) Use FailedPrecondition if the client should not retry until
  91. // the system state has been explicitly fixed. E.g., if an "rmdir"
  92. // fails because the directory is non-empty, FailedPrecondition
  93. // should be returned since the client should not retry unless
  94. // they have first fixed up the directory by deleting files from it.
  95. // (d) Use FailedPrecondition if the client performs conditional
  96. // REST Get/Update/Delete on a resource and the resource on the
  97. // server does not match the condition. E.g., conflicting
  98. // read-modify-write on the same resource.
  99. FailedPrecondition Code = 9
  100. // Aborted indicates the operation was aborted, typically due to a
  101. // concurrency issue like sequencer check failures, transaction aborts,
  102. // etc.
  103. //
  104. // See litmus test above for deciding between FailedPrecondition,
  105. // Aborted, and Unavailable.
  106. Aborted Code = 10
  107. // OutOfRange means operation was attempted past the valid range.
  108. // E.g., seeking or reading past end of file.
  109. //
  110. // Unlike InvalidArgument, this error indicates a problem that may
  111. // be fixed if the system state changes. For example, a 32-bit file
  112. // system will generate InvalidArgument if asked to read at an
  113. // offset that is not in the range [0,2^32-1], but it will generate
  114. // OutOfRange if asked to read from an offset past the current
  115. // file size.
  116. //
  117. // There is a fair bit of overlap between FailedPrecondition and
  118. // OutOfRange. We recommend using OutOfRange (the more specific
  119. // error) when it applies so that callers who are iterating through
  120. // a space can easily look for an OutOfRange error to detect when
  121. // they are done.
  122. OutOfRange Code = 11
  123. // Unimplemented indicates operation is not implemented or not
  124. // supported/enabled in this service.
  125. Unimplemented Code = 12
  126. // Internal errors. Means some invariants expected by underlying
  127. // system has been broken. If you see one of these errors,
  128. // something is very broken.
  129. Internal Code = 13
  130. // Unavailable indicates the service is currently unavailable.
  131. // This is a most likely a transient condition and may be corrected
  132. // by retrying with a backoff.
  133. //
  134. // See litmus test above for deciding between FailedPrecondition,
  135. // Aborted, and Unavailable.
  136. Unavailable Code = 14
  137. // DataLoss indicates unrecoverable data loss or corruption.
  138. DataLoss Code = 15
  139. )