xref: /aosp_15_r20/external/grpc-grpc/include/grpc/status.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 /*
2  *
3  * Copyright 2015 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 #ifndef GRPC_STATUS_H
20 #define GRPC_STATUS_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef enum {
29   /** Not an error; returned on success */
30   GRPC_STATUS_OK = 0,
31 
32   /** The operation was cancelled (typically by the caller). */
33   GRPC_STATUS_CANCELLED = 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   GRPC_STATUS_UNKNOWN = 2,
41 
42   /** Client specified an invalid argument.  Note that this differs
43      from FAILED_PRECONDITION.  INVALID_ARGUMENT indicates arguments
44      that are problematic regardless of the state of the system
45      (e.g., a malformed file name). */
46   GRPC_STATUS_INVALID_ARGUMENT = 3,
47 
48   /** Deadline expired before operation could complete.  For operations
49      that change the state of the system, this error may be returned
50      even if the operation has completed successfully.  For example, a
51      successful response from a server could have been delayed long
52      enough for the deadline to expire. */
53   GRPC_STATUS_DEADLINE_EXCEEDED = 4,
54 
55   /** Some requested entity (e.g., file or directory) was not found. */
56   GRPC_STATUS_NOT_FOUND = 5,
57 
58   /** Some entity that we attempted to create (e.g., file or directory)
59      already exists. */
60   GRPC_STATUS_ALREADY_EXISTS = 6,
61 
62   /** The caller does not have permission to execute the specified
63      operation.  PERMISSION_DENIED must not be used for rejections
64      caused by exhausting some resource (use RESOURCE_EXHAUSTED
65      instead for those errors).  PERMISSION_DENIED must not be
66      used if the caller can not be identified (use UNAUTHENTICATED
67      instead for those errors). */
68   GRPC_STATUS_PERMISSION_DENIED = 7,
69 
70   /** The request does not have valid authentication credentials for the
71      operation. */
72   GRPC_STATUS_UNAUTHENTICATED = 16,
73 
74   /** Some resource has been exhausted, perhaps a per-user quota, or
75      perhaps the entire file system is out of space. */
76   GRPC_STATUS_RESOURCE_EXHAUSTED = 8,
77 
78   /** Operation was rejected because the system is not in a state
79      required for the operation's execution.  For example, directory
80      to be deleted may be non-empty, an rmdir operation is applied to
81      a non-directory, etc.
82 
83      A litmus test that may help a service implementor in deciding
84      between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
85       (a) Use UNAVAILABLE if the client can retry just the failing call.
86       (b) Use ABORTED if the client should retry at a higher-level
87           (e.g., restarting a read-modify-write sequence).
88       (c) Use FAILED_PRECONDITION if the client should not retry until
89           the system state has been explicitly fixed.  E.g., if an "rmdir"
90           fails because the directory is non-empty, FAILED_PRECONDITION
91           should be returned since the client should not retry unless
92           they have first fixed up the directory by deleting files from it.
93       (d) Use FAILED_PRECONDITION if the client performs conditional
94           REST Get/Update/Delete on a resource and the resource on the
95           server does not match the condition. E.g., conflicting
96           read-modify-write on the same resource. */
97   GRPC_STATUS_FAILED_PRECONDITION = 9,
98 
99   /** The operation was aborted, typically due to a concurrency issue
100      like sequencer check failures, transaction aborts, etc.
101 
102      See litmus test above for deciding between FAILED_PRECONDITION,
103      ABORTED, and UNAVAILABLE. */
104   GRPC_STATUS_ABORTED = 10,
105 
106   /** Operation was attempted past the valid range.  E.g., seeking or
107      reading past end of file.
108 
109      Unlike INVALID_ARGUMENT, this error indicates a problem that may
110      be fixed if the system state changes. For example, a 32-bit file
111      system will generate INVALID_ARGUMENT if asked to read at an
112      offset that is not in the range [0,2^32-1], but it will generate
113      OUT_OF_RANGE if asked to read from an offset past the current
114      file size.
115 
116      There is a fair bit of overlap between FAILED_PRECONDITION and
117      OUT_OF_RANGE.  We recommend using OUT_OF_RANGE (the more specific
118      error) when it applies so that callers who are iterating through
119      a space can easily look for an OUT_OF_RANGE error to detect when
120      they are done. */
121   GRPC_STATUS_OUT_OF_RANGE = 11,
122 
123   /** Operation is not implemented or not supported/enabled in this service. */
124   GRPC_STATUS_UNIMPLEMENTED = 12,
125 
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   GRPC_STATUS_INTERNAL = 13,
130 
131   /** The service is currently unavailable.  This is a most likely a
132      transient condition and may be corrected by retrying with
133      a backoff. Note that it is not always safe to retry non-idempotent
134      operations.
135 
136      WARNING: Although data MIGHT not have been transmitted when this
137      status occurs, there is NOT A GUARANTEE that the server has not seen
138      anything. So in general it is unsafe to retry on this status code
139      if the call is non-idempotent.
140 
141      See litmus test above for deciding between FAILED_PRECONDITION,
142      ABORTED, and UNAVAILABLE. */
143   GRPC_STATUS_UNAVAILABLE = 14,
144 
145   /** Unrecoverable data loss or corruption. */
146   GRPC_STATUS_DATA_LOSS = 15,
147 
148   /** Force users to include a default branch: */
149   GRPC_STATUS__DO_NOT_USE = -1
150 } grpc_status_code;
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif /* GRPC_STATUS_H */
157