Skip to content

Commit 3405381

Browse files
authored
codes: document which error codes can be returned by the framework (grpc#3699)
This commit essentially copies the information from the second section of the gRPC core documentation about status codes at https://grpc.github.io/grpc/core/md_doc_statuscodes.html into the Go documentation of the status codes, to increase visibility.
1 parent a86c873 commit 3405381

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

codes/codes.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,49 @@ const (
3333
OK Code = 0
3434

3535
// Canceled indicates the operation was canceled (typically by the caller).
36+
//
37+
// The gRPC framework will generate this error code when cancellation
38+
// is requested.
3639
Canceled Code = 1
3740

3841
// Unknown error. An example of where this error may be returned is
3942
// if a Status value received from another address space belongs to
4043
// an error-space that is not known in this address space. Also
4144
// errors raised by APIs that do not return enough error information
4245
// may be converted to this error.
46+
//
47+
// The gRPC framework will generate this error code in the above two
48+
// mentioned cases.
4349
Unknown Code = 2
4450

4551
// InvalidArgument indicates client specified an invalid argument.
4652
// Note that this differs from FailedPrecondition. It indicates arguments
4753
// that are problematic regardless of the state of the system
4854
// (e.g., a malformed file name).
55+
//
56+
// This error code will not be generated by the gRPC framework.
4957
InvalidArgument Code = 3
5058

5159
// DeadlineExceeded means operation expired before completion.
5260
// For operations that change the state of the system, this error may be
5361
// returned even if the operation has completed successfully. For
5462
// example, a successful response from a server could have been delayed
5563
// long enough for the deadline to expire.
64+
//
65+
// The gRPC framework will generate this error code when the deadline is
66+
// exceeded.
5667
DeadlineExceeded Code = 4
5768

5869
// NotFound means some requested entity (e.g., file or directory) was
5970
// not found.
71+
//
72+
// This error code will not be generated by the gRPC framework.
6073
NotFound Code = 5
6174

6275
// AlreadyExists means an attempt to create an entity failed because one
6376
// already exists.
77+
//
78+
// This error code will not be generated by the gRPC framework.
6479
AlreadyExists Code = 6
6580

6681
// PermissionDenied indicates the caller does not have permission to
@@ -69,10 +84,17 @@ const (
6984
// instead for those errors). It must not be
7085
// used if the caller cannot be identified (use Unauthenticated
7186
// instead for those errors).
87+
//
88+
// This error code will not be generated by the gRPC core framework,
89+
// but expect authentication middleware to use it.
7290
PermissionDenied Code = 7
7391

7492
// ResourceExhausted indicates some resource has been exhausted, perhaps
7593
// a per-user quota, or perhaps the entire file system is out of space.
94+
//
95+
// This error code will be generated by the gRPC framework in
96+
// out-of-memory and server overload situations, or when a message is
97+
// larger than the configured maximum size.
7698
ResourceExhausted Code = 8
7799

78100
// FailedPrecondition indicates operation was rejected because the
@@ -94,6 +116,8 @@ const (
94116
// REST Get/Update/Delete on a resource and the resource on the
95117
// server does not match the condition. E.g., conflicting
96118
// read-modify-write on the same resource.
119+
//
120+
// This error code will not be generated by the gRPC framework.
97121
FailedPrecondition Code = 9
98122

99123
// Aborted indicates the operation was aborted, typically due to a
@@ -102,6 +126,8 @@ const (
102126
//
103127
// See litmus test above for deciding between FailedPrecondition,
104128
// Aborted, and Unavailable.
129+
//
130+
// This error code will not be generated by the gRPC framework.
105131
Aborted Code = 10
106132

107133
// OutOfRange means operation was attempted past the valid range.
@@ -119,15 +145,26 @@ const (
119145
// error) when it applies so that callers who are iterating through
120146
// a space can easily look for an OutOfRange error to detect when
121147
// they are done.
148+
//
149+
// This error code will not be generated by the gRPC framework.
122150
OutOfRange Code = 11
123151

124152
// Unimplemented indicates operation is not implemented or not
125153
// supported/enabled in this service.
154+
//
155+
// This error code will be generated by the gRPC framework. Most
156+
// commonly, you will see this error code when a method implementation
157+
// is missing on the server. It can also be generated for unknown
158+
// compression algorithms or a disagreement as to whether an RPC should
159+
// be streaming.
126160
Unimplemented Code = 12
127161

128162
// Internal errors. Means some invariants expected by underlying
129163
// system has been broken. If you see one of these errors,
130164
// something is very broken.
165+
//
166+
// This error code will be generated by the gRPC framework in several
167+
// internal error conditions.
131168
Internal Code = 13
132169

133170
// Unavailable indicates the service is currently unavailable.
@@ -137,13 +174,22 @@ const (
137174
//
138175
// See litmus test above for deciding between FailedPrecondition,
139176
// Aborted, and Unavailable.
177+
//
178+
// This error code will be generated by the gRPC framework during
179+
// abrupt shutdown of a server process or network connection.
140180
Unavailable Code = 14
141181

142182
// DataLoss indicates unrecoverable data loss or corruption.
183+
//
184+
// This error code will not be generated by the gRPC framework.
143185
DataLoss Code = 15
144186

145187
// Unauthenticated indicates the request does not have valid
146188
// authentication credentials for the operation.
189+
//
190+
// The gRPC framework will generate this error code when the
191+
// authentication metadata is invalid or a Credentials callback fails,
192+
// but also expect authentication middleware to generate it.
147193
Unauthenticated Code = 16
148194

149195
_maxCode = 17

0 commit comments

Comments
 (0)