[#absl-StatusCode]
= xref:absl.adoc[absl]::StatusCode
:relfileprefix: ../
:mrdocs:

An enumerated type indicating either no error (&quot;OK&quot;) or an error condition&period;

== Synopsis

Declared in `&lt;absl&sol;status&sol;status&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
enum class StatusCode : int;
----

== Description

In most cases, an `absl&colon;&colon;Status` indicates a recoverable error, and the purpose of signalling an error is to indicate what action to take in response to that error&period; These error codes map to the proto RPC error codes indicated in https&colon;&sol;&sol;cloud&period;google&period;com&sol;apis&sol;design&sol;errors&period;

The errors listed below are the canonical errors associated with `absl&colon;&colon;Status` and are used throughout the codebase&period; As a result, these error codes are somewhat generic&period;

In general, try to return the most specific error that applies if more than one error may pertain&period; For example, prefer `kOutOfRange` over `kFailedPrecondition` if both codes apply&period; Similarly prefer `kNotFound` or `kAlreadyExists` over `kFailedPrecondition`&period;

Because these errors may cross RPC boundaries, these codes are tied to the `google&period;rpc&period;Code` definitions within https&colon;&sol;&sol;github&period;com&sol;googleapis&sol;googleapis&sol;blob&sol;master&sol;google&sol;rpc&sol;code&period;proto The string value of these RPC codes is denoted within each enum below&period;

If your error handling code requires more context, you can attach payloads to your status&period; See `absl&colon;&colon;Status&colon;&colon;SetPayload()` and `absl&colon;&colon;Status&colon;&colon;GetPayload()` below&period;

== Members

[cols="1,4"]
|===
| Name| Description
| `kOk` 
| (gRPC code &quot;OK&quot;) does not indicate an error&semi; this value is returned on success&period; It is typical to check for this value before proceeding on any given call across an API or RPC boundary&period; To check this value, use the `absl&colon;&colon;Status&colon;&colon;ok()` member function rather than inspecting the raw code&period;
| `kCancelled` 
| (gRPC code &quot;CANCELLED&quot;) indicates the operation was cancelled, typically by the caller&period;
| `kUnknown` 
| (gRPC code &quot;UNKNOWN&quot;) indicates an unknown error occurred&period; In general, more specific errors should be raised, if possible&period; Errors raised by APIs that do not return enough error information may be converted to this error&period;
| `kInvalidArgument` 
| (gRPC code &quot;INVALID&lowbar;ARGUMENT&quot;) indicates the caller specified an invalid argument, such as a malformed filename&period; Note that use of such errors should be narrowly limited to indicate the invalid nature of the arguments themselves&period; Errors with validly formed arguments that may cause errors with the state of the receiving system should be denoted with `kFailedPrecondition` instead&period;
| `kDeadlineExceeded` 
| (gRPC code &quot;DEADLINE&lowbar;EXCEEDED&quot;) indicates a deadline expired before the operation could complete&period; For operations that may change state within a system, this error may be returned even if the operation has completed successfully&period; For example, a successful response from a server could have been delayed long enough for the deadline to expire&period;
| `kNotFound` 
| (gRPC code &quot;NOT&lowbar;FOUND&quot;) indicates some requested entity (such as a file or directory) was not found&period;
| `kAlreadyExists` 
| (gRPC code &quot;ALREADY&lowbar;EXISTS&quot;) indicates that the entity a caller attempted to create (such as a file or directory) is already present&period;
| `kPermissionDenied` 
| (gRPC code &quot;PERMISSION&lowbar;DENIED&quot;) indicates that the caller does not have permission to execute the specified operation&period; Note that this error is different than an error due to an _un_authenticated user&period; This error code does not imply the request is valid or the requested entity exists or satisfies any other pre&hyphen;conditions&period;
| `kResourceExhausted` 
| (gRPC code &quot;RESOURCE&lowbar;EXHAUSTED&quot;) indicates some resource has been exhausted, perhaps a per&hyphen;user quota, or perhaps the entire file system is out of space&period;
| `kFailedPrecondition` 
| (gRPC code &quot;FAILED&lowbar;PRECONDITION&quot;) indicates that the operation was rejected because the system is not in a state required for the operation&apos;s execution&period; For example, a directory to be deleted may be non&hyphen;empty, an &quot;rmdir&quot; operation is applied to a non&hyphen;directory, etc&period;
| `kAborted` 
| (gRPC code &quot;ABORTED&quot;) indicates the operation was aborted, typically due to a concurrency issue such as a sequencer check failure or a failed transaction&period;
| `kOutOfRange` 
| (gRPC code &quot;OUT&lowbar;OF&lowbar;RANGE&quot;) indicates the operation was attempted past the valid range, such as seeking or reading past an end&hyphen;of&hyphen;file&period;
| `kUnimplemented` 
| (gRPC code &quot;UNIMPLEMENTED&quot;) indicates the operation is not implemented or supported in this service&period; In this case, the operation should not be re&hyphen;attempted&period;
| `kInternal` 
| (gRPC code &quot;INTERNAL&quot;) indicates an internal error has occurred and some invariants expected by the underlying system have not been satisfied&period; This error code is reserved for serious errors&period;
| `kUnavailable` 
| (gRPC code &quot;UNAVAILABLE&quot;) indicates the service is currently unavailable and that this is most likely a transient condition&period; An error such as this can be corrected by retrying with a backoff scheme&period; Note that it is not always safe to retry non&hyphen;idempotent operations&period;
| `kDataLoss` 
| (gRPC code &quot;DATA&lowbar;LOSS&quot;) indicates that unrecoverable data loss or corruption has occurred&period; As this error is serious, proper alerting should be attached to errors such as this&period;
| `kUnauthenticated` 
| (gRPC code &quot;UNAUTHENTICATED&quot;) indicates that the request does not have valid authentication credentials for the operation&period; Correct the authentication and try again&period;
| `kDoNotUseReservedForFutureExpansionUseDefaultInSwitchInstead&lowbar;` 
| Reserved for future expansion&semi; do not use&period;
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/ErrnoToStatusCode.adoc[`ErrnoToStatusCode`]
| Returns the StatusCode for `error&lowbar;number`, which should be an `errno` value&period;
| xref:absl/StatusCodeToString.adoc[`StatusCodeToString`]
| Returns the name for the status code, or &quot;&quot; if it is an unknown value&period;
| xref:absl/StatusCodeToStringView.adoc[`StatusCodeToStringView`]
| Same as StatusCodeToString(), but returns a string&lowbar;view&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
