| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2014 gRPC authors. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
// Package codes defines the canonical error codes used by gRPC. It is |
| 20 |
// consistent across various languages. |
| 21 |
package codes // import "google.golang.org/grpc/codes" |
| 22 |
|
| 23 |
// A Code is an unsigned 32-bit error code as defined in the gRPC spec. |
| 24 |
type Code uint32 |
| 25 |
|
| 26 |
//go:generate stringer -type=Code |
| 27 |
|
| 28 |
const ( |
| 29 |
// OK is returned on success. |
| 30 |
OK Code = 0 |
| 31 |
|
| 32 |
// Canceled indicates the operation was canceled (typically by the caller). |
| 33 |
Canceled Code = 1 |
| 34 |
|
| 35 |
// Unknown error. An example of where this error may be returned is |
| 36 |
// if a Status value received from another address space belongs to |
| 37 |
// an error-space that is not known in this address space. Also |
| 38 |
// errors raised by APIs that do not return enough error information |
| 39 |
// may be converted to this error. |
| 40 |
Unknown Code = 2 |
| 41 |
|
| 42 |
// InvalidArgument indicates client specified an invalid argument. |
| 43 |
// Note that this differs from FailedPrecondition. It indicates arguments |
| 44 |
// that are problematic regardless of the state of the system |
| 45 |
// (e.g., a malformed file name). |
| 46 |
InvalidArgument Code = 3 |
| 47 |
|
| 48 |
// DeadlineExceeded means operation expired before completion. |
| 49 |
// For operations that change the state of the system, this error may be |
| 50 |
// returned even if the operation has completed successfully. For |
| 51 |
// example, a successful response from a server could have been delayed |
| 52 |
// long enough for the deadline to expire. |
| 53 |
DeadlineExceeded Code = 4 |
| 54 |
|
| 55 |
// NotFound means some requested entity (e.g., file or directory) was |
| 56 |
// not found. |
| 57 |
NotFound Code = 5 |
| 58 |
|
| 59 |
// AlreadyExists means an attempt to create an entity failed because one |
| 60 |
// already exists. |
| 61 |
AlreadyExists Code = 6 |
| 62 |
|
| 63 |
// PermissionDenied indicates the caller does not have permission to |
| 64 |
// execute the specified operation. It must not be used for rejections |
| 65 |
// caused by exhausting some resource (use ResourceExhausted |
| 66 |
// instead for those errors). It must not be |
| 67 |
// used if the caller cannot be identified (use Unauthenticated |
| 68 |
// instead for those errors). |
| 69 |
PermissionDenied Code = 7 |
| 70 |
|
| 71 |
// Unauthenticated indicates the request does not have valid |
| 72 |
// authentication credentials for the operation. |
| 73 |
Unauthenticated Code = 16 |
| 74 |
|
| 75 |
// ResourceExhausted indicates some resource has been exhausted, perhaps |
| 76 |
// a per-user quota, or perhaps the entire file system is out of space. |
| 77 |
ResourceExhausted Code = 8 |
| 78 |
|
| 79 |
// FailedPrecondition indicates operation was rejected because the |
| 80 |
// system is not in a state required for the operation's execution. |
| 81 |
// For example, directory to be deleted may be non-empty, an rmdir |
| 82 |
// operation is applied to a non-directory, etc. |
| 83 |
// |
| 84 |
// A litmus test that may help a service implementor in deciding |
| 85 |
// between FailedPrecondition, Aborted, and Unavailable: |
| 86 |
// (a) Use Unavailable if the client can retry just the failing call. |
| 87 |
// (b) Use Aborted if the client should retry at a higher-level |
| 88 |
// (e.g., restarting a read-modify-write sequence). |
| 89 |
// (c) Use FailedPrecondition if the client should not retry until |
| 90 |
// the system state has been explicitly fixed. E.g., if an "rmdir" |
| 91 |
// fails because the directory is non-empty, FailedPrecondition |
| 92 |
// should be returned since the client should not retry unless |
| 93 |
// they have first fixed up the directory by deleting files from it. |
| 94 |
// (d) Use FailedPrecondition if the client performs conditional |
| 95 |
// REST Get/Update/Delete on a resource and the resource on the |
| 96 |
// server does not match the condition. E.g., conflicting |
| 97 |
// read-modify-write on the same resource. |
| 98 |
FailedPrecondition Code = 9 |
| 99 |
|
| 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 |
|
| 108 |
// OutOfRange means operation was attempted past the valid range. |
| 109 |
// E.g., seeking or reading past end of file. |
| 110 |
// |
| 111 |
// Unlike InvalidArgument, this error indicates a problem that may |
| 112 |
// be fixed if the system state changes. For example, a 32-bit file |
| 113 |
// system will generate InvalidArgument if asked to read at an |
| 114 |
// offset that is not in the range [0,2^32-1], but it will generate |
| 115 |
// OutOfRange if asked to read from an offset past the current |
| 116 |
// file size. |
| 117 |
// |
| 118 |
// There is a fair bit of overlap between FailedPrecondition and |
| 119 |
// OutOfRange. We recommend using OutOfRange (the more specific |
| 120 |
// error) when it applies so that callers who are iterating through |
| 121 |
// a space can easily look for an OutOfRange error to detect when |
| 122 |
// they are done. |
| 123 |
OutOfRange Code = 11 |
| 124 |
|
| 125 |
// Unimplemented indicates operation is not implemented or not |
| 126 |
// supported/enabled in this service. |
| 127 |
Unimplemented Code = 12 |
| 128 |
|
| 129 |
// Internal errors. Means some invariants expected by underlying |
| 130 |
// system has been broken. If you see one of these errors, |
| 131 |
// something is very broken. |
| 132 |
Internal Code = 13 |
| 133 |
|
| 134 |
// Unavailable indicates the service is currently unavailable. |
| 135 |
// This is a most likely a transient condition and may be corrected |
| 136 |
// by retrying with a backoff. |
| 137 |
// |
| 138 |
// See litmus test above for deciding between FailedPrecondition, |
| 139 |
// Aborted, and Unavailable. |
| 140 |
Unavailable Code = 14 |
| 141 |
|
| 142 |
// DataLoss indicates unrecoverable data loss or corruption. |
| 143 |
DataLoss Code = 15 |
| 144 |
) |