diff options
Diffstat (limited to 'vendor/google.golang.org/grpc/codes/codes.go')
-rw-r--r-- | vendor/google.golang.org/grpc/codes/codes.go | 79 |
1 files changed, 66 insertions, 13 deletions
diff --git a/vendor/google.golang.org/grpc/codes/codes.go b/vendor/google.golang.org/grpc/codes/codes.go index 21e7733..d9b9d57 100644 --- a/vendor/google.golang.org/grpc/codes/codes.go +++ b/vendor/google.golang.org/grpc/codes/codes.go | |||
@@ -20,11 +20,14 @@ | |||
20 | // consistent across various languages. | 20 | // consistent across various languages. |
21 | package codes // import "google.golang.org/grpc/codes" | 21 | package codes // import "google.golang.org/grpc/codes" |
22 | 22 | ||
23 | import ( | ||
24 | "fmt" | ||
25 | "strconv" | ||
26 | ) | ||
27 | |||
23 | // A Code is an unsigned 32-bit error code as defined in the gRPC spec. | 28 | // A Code is an unsigned 32-bit error code as defined in the gRPC spec. |
24 | type Code uint32 | 29 | type Code uint32 |
25 | 30 | ||
26 | //go:generate stringer -type=Code | ||
27 | |||
28 | const ( | 31 | const ( |
29 | // OK is returned on success. | 32 | // OK is returned on success. |
30 | OK Code = 0 | 33 | OK Code = 0 |
@@ -32,9 +35,9 @@ const ( | |||
32 | // Canceled indicates the operation was canceled (typically by the caller). | 35 | // Canceled indicates the operation was canceled (typically by the caller). |
33 | Canceled Code = 1 | 36 | Canceled Code = 1 |
34 | 37 | ||
35 | // Unknown error. An example of where this error may be returned is | 38 | // Unknown error. An example of where this error may be returned is |
36 | // if a Status value received from another address space belongs to | 39 | // if a Status value received from another address space belongs to |
37 | // an error-space that is not known in this address space. Also | 40 | // an error-space that is not known in this address space. Also |
38 | // errors raised by APIs that do not return enough error information | 41 | // errors raised by APIs that do not return enough error information |
39 | // may be converted to this error. | 42 | // may be converted to this error. |
40 | Unknown Code = 2 | 43 | Unknown Code = 2 |
@@ -63,15 +66,11 @@ const ( | |||
63 | // PermissionDenied indicates the caller does not have permission to | 66 | // PermissionDenied indicates the caller does not have permission to |
64 | // execute the specified operation. It must not be used for rejections | 67 | // execute the specified operation. It must not be used for rejections |
65 | // caused by exhausting some resource (use ResourceExhausted | 68 | // caused by exhausting some resource (use ResourceExhausted |
66 | // instead for those errors). It must not be | 69 | // instead for those errors). It must not be |
67 | // used if the caller cannot be identified (use Unauthenticated | 70 | // used if the caller cannot be identified (use Unauthenticated |
68 | // instead for those errors). | 71 | // instead for those errors). |
69 | PermissionDenied Code = 7 | 72 | PermissionDenied Code = 7 |
70 | 73 | ||
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 | 74 | // ResourceExhausted indicates some resource has been exhausted, perhaps |
76 | // a per-user quota, or perhaps the entire file system is out of space. | 75 | // a per-user quota, or perhaps the entire file system is out of space. |
77 | ResourceExhausted Code = 8 | 76 | ResourceExhausted Code = 8 |
@@ -87,7 +86,7 @@ const ( | |||
87 | // (b) Use Aborted if the client should retry at a higher-level | 86 | // (b) Use Aborted if the client should retry at a higher-level |
88 | // (e.g., restarting a read-modify-write sequence). | 87 | // (e.g., restarting a read-modify-write sequence). |
89 | // (c) Use FailedPrecondition if the client should not retry until | 88 | // (c) Use FailedPrecondition if the client should not retry until |
90 | // the system state has been explicitly fixed. E.g., if an "rmdir" | 89 | // the system state has been explicitly fixed. E.g., if an "rmdir" |
91 | // fails because the directory is non-empty, FailedPrecondition | 90 | // fails because the directory is non-empty, FailedPrecondition |
92 | // should be returned since the client should not retry unless | 91 | // should be returned since the client should not retry unless |
93 | // they have first fixed up the directory by deleting files from it. | 92 | // they have first fixed up the directory by deleting files from it. |
@@ -116,7 +115,7 @@ const ( | |||
116 | // file size. | 115 | // file size. |
117 | // | 116 | // |
118 | // There is a fair bit of overlap between FailedPrecondition and | 117 | // There is a fair bit of overlap between FailedPrecondition and |
119 | // OutOfRange. We recommend using OutOfRange (the more specific | 118 | // OutOfRange. We recommend using OutOfRange (the more specific |
120 | // error) when it applies so that callers who are iterating through | 119 | // error) when it applies so that callers who are iterating through |
121 | // a space can easily look for an OutOfRange error to detect when | 120 | // a space can easily look for an OutOfRange error to detect when |
122 | // they are done. | 121 | // they are done. |
@@ -126,8 +125,8 @@ const ( | |||
126 | // supported/enabled in this service. | 125 | // supported/enabled in this service. |
127 | Unimplemented Code = 12 | 126 | Unimplemented Code = 12 |
128 | 127 | ||
129 | // Internal errors. Means some invariants expected by underlying | 128 | // Internal errors. Means some invariants expected by underlying |
130 | // system has been broken. If you see one of these errors, | 129 | // system has been broken. If you see one of these errors, |
131 | // something is very broken. | 130 | // something is very broken. |
132 | Internal Code = 13 | 131 | Internal Code = 13 |
133 | 132 | ||
@@ -141,4 +140,58 @@ const ( | |||
141 | 140 | ||
142 | // DataLoss indicates unrecoverable data loss or corruption. | 141 | // DataLoss indicates unrecoverable data loss or corruption. |
143 | DataLoss Code = 15 | 142 | DataLoss Code = 15 |
143 | |||
144 | // Unauthenticated indicates the request does not have valid | ||
145 | // authentication credentials for the operation. | ||
146 | Unauthenticated Code = 16 | ||
147 | |||
148 | _maxCode = 17 | ||
144 | ) | 149 | ) |
150 | |||
151 | var strToCode = map[string]Code{ | ||
152 | `"OK"`: OK, | ||
153 | `"CANCELLED"`:/* [sic] */ Canceled, | ||
154 | `"UNKNOWN"`: Unknown, | ||
155 | `"INVALID_ARGUMENT"`: InvalidArgument, | ||
156 | `"DEADLINE_EXCEEDED"`: DeadlineExceeded, | ||
157 | `"NOT_FOUND"`: NotFound, | ||
158 | `"ALREADY_EXISTS"`: AlreadyExists, | ||
159 | `"PERMISSION_DENIED"`: PermissionDenied, | ||
160 | `"RESOURCE_EXHAUSTED"`: ResourceExhausted, | ||
161 | `"FAILED_PRECONDITION"`: FailedPrecondition, | ||
162 | `"ABORTED"`: Aborted, | ||
163 | `"OUT_OF_RANGE"`: OutOfRange, | ||
164 | `"UNIMPLEMENTED"`: Unimplemented, | ||
165 | `"INTERNAL"`: Internal, | ||
166 | `"UNAVAILABLE"`: Unavailable, | ||
167 | `"DATA_LOSS"`: DataLoss, | ||
168 | `"UNAUTHENTICATED"`: Unauthenticated, | ||
169 | } | ||
170 | |||
171 | // UnmarshalJSON unmarshals b into the Code. | ||
172 | func (c *Code) UnmarshalJSON(b []byte) error { | ||
173 | // From json.Unmarshaler: By convention, to approximate the behavior of | ||
174 | // Unmarshal itself, Unmarshalers implement UnmarshalJSON([]byte("null")) as | ||
175 | // a no-op. | ||
176 | if string(b) == "null" { | ||
177 | return nil | ||
178 | } | ||
179 | if c == nil { | ||
180 | return fmt.Errorf("nil receiver passed to UnmarshalJSON") | ||
181 | } | ||
182 | |||
183 | if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil { | ||
184 | if ci >= _maxCode { | ||
185 | return fmt.Errorf("invalid code: %q", ci) | ||
186 | } | ||
187 | |||
188 | *c = Code(ci) | ||
189 | return nil | ||
190 | } | ||
191 | |||
192 | if jc, ok := strToCode[string(b)]; ok { | ||
193 | *c = jc | ||
194 | return nil | ||
195 | } | ||
196 | return fmt.Errorf("invalid code: %q", string(b)) | ||
197 | } | ||