Code in conjunction with an
optional descriptive message. Instances of Status are created by starting with the
template for the appropriate Status.Code and supplementing it with additional
information: Status.NOT_FOUND.withDescription("Could not find 'important_file.txt'");
For clients, every remote call will return a status on completion. In the case of errors this
status may be propagated to blocking stubs as a RuntimeException or to a listener as an
explicit parameter.
Similarly servers can report a status by throwing StatusRuntimeException
or by passing the status to a callback.
Utility functions are provided to convert a status to an exception and to extract them back out.
Extended descriptions, including a list of codes that should not be generated by the library, can be found at doc/statuscodes.md
| Modifier and Type | Class and Description |
|---|---|
| public static enum | Status.Code
The set of canonical status codes. |
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final Status | ABORTED
The operation was aborted, typically due to a concurrency issue like sequencer check failures,
transaction aborts, etc. See |
| public static final Status | ALREADY_EXISTS
Some entity that we attempted to create (e.g., file or directory) already exists. |
| public static final Status | CANCELLED
The operation was cancelled (typically by the caller). |
| private final Throwable | |
| private final Status. | |
| pack-priv static final Metadata. | CODE_KEY
Key to bind status code to trailing metadata. |
| public static final Status | DATA_LOSS
Unrecoverable data loss or corruption. |
| public static final Status | DEADLINE_EXCEEDED
Deadline expired before operation could complete. |
| private final String | |
| private static final boolean | |
| public static final Status | FAILED_PRECONDITION
Operation was rejected because the system is not in a state required for the operation's execution. |
| public static final Status | INTERNAL
Internal errors. |
| public static final Status | INVALID_ARGUMENT
Client specified an invalid argument. |
| pack-priv static final Metadata. | MESSAGE_KEY
Key to bind status message to trailing metadata. |
| public static final Status | NOT_FOUND
Some requested entity (e.g., file or directory) was not found. |
| public static final Status | OK
The operation completed successfully. |
| public static final Status | OUT_OF_RANGE
Operation was attempted past the valid range. |
| public static final Status | PERMISSION_DENIED
The caller does not have permission to execute the specified operation. |
| public static final Status | RESOURCE_EXHAUSTED
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. |
| private static final List | |
| private static final Metadata. | STATUS_MESSAGE_MARSHALLER
Marshals status messages for ( |
| private static final String | |
| public static final Status | UNAUTHENTICATED
The request does not have valid authentication credentials for the operation. |
| public static final Status | UNAVAILABLE
The service is currently unavailable. |
| public static final Status | UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service. |
| public static final Status | UNKNOWN
Unknown error. |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public StatusException | |
| public StatusException | asException(Metadata trailers)
Same as |
| public StatusRuntimeException | |
| public StatusRuntimeException | asRuntimeException(Metadata trailers)
Same as |
| public Status | augmentDescription(String additionalDetail)
Create a derived instance of |
| private static List | |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| pack-priv static String | |
| public static Status | |
| public static Status | |
| private static Status | |
| private static Status | |
| public static Status | Returns: non-null statusExtract an error |
| public Throwable | |
| public Status. | |
| public String | |
| public int | |
| public boolean | |
| public String | toString()
Overrides java. |
| public static Metadata | Returns: the trailers ornull if not found.Extract an error trailers from the causal chain of a |
| public Status | |
| public Status |
| ABORTED | back to summary |
|---|---|
| public static final Status ABORTED The operation was aborted, typically due to a concurrency issue like sequencer check failures,
transaction aborts, etc. See | |
| ALREADY_EXISTS | back to summary |
|---|---|
| public static final Status ALREADY_EXISTS Some entity that we attempted to create (e.g., file or directory) already exists. | |
| CANCELLED | back to summary |
|---|---|
| public static final Status CANCELLED The operation was cancelled (typically by the caller). | |
| cause | back to summary |
|---|---|
| private final Throwable cause | |
| code | back to summary |
|---|---|
| private final Status. | |
| CODE_KEY | back to summary |
|---|---|
| pack-priv static final Metadata. Key to bind status code to trailing metadata. | |
| DATA_LOSS | back to summary |
|---|---|
| public static final Status DATA_LOSS Unrecoverable data loss or corruption. | |
| DEADLINE_EXCEEDED | back to summary |
|---|---|
| public static final Status DEADLINE_EXCEEDED Deadline expired before operation could complete. See | |
| description | back to summary |
|---|---|
| private final String description | |
| FAIL_ON_EQUALS_FOR_TEST | back to summary |
|---|---|
| private static final boolean FAIL_ON_EQUALS_FOR_TEST | |
| FAILED_PRECONDITION | back to summary |
|---|---|
| public static final Status FAILED_PRECONDITION Operation was rejected because the system is not in a state required for the operation's
execution. See | |
| INTERNAL | back to summary |
|---|---|
| public static final Status INTERNAL Internal errors. See | |
| INVALID_ARGUMENT | back to summary |
|---|---|
| public static final Status INVALID_ARGUMENT Client specified an invalid argument. See | |
| MESSAGE_KEY | back to summary |
|---|---|
| pack-priv static final Metadata. Key to bind status message to trailing metadata. | |
| NOT_FOUND | back to summary |
|---|---|
| public static final Status NOT_FOUND Some requested entity (e.g., file or directory) was not found. | |
| OK | back to summary |
|---|---|
| public static final Status OK The operation completed successfully. | |
| OUT_OF_RANGE | back to summary |
|---|---|
| public static final Status OUT_OF_RANGE Operation was attempted past the valid range. See | |
| PERMISSION_DENIED | back to summary |
|---|---|
| public static final Status PERMISSION_DENIED The caller does not have permission to execute the specified operation. See | |
| RESOURCE_EXHAUSTED | back to summary |
|---|---|
| public static final Status RESOURCE_EXHAUSTED Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. | |
| STATUS_LIST | back to summary |
|---|---|
| private static final List<Status> STATUS_LIST | |
| STATUS_MESSAGE_MARSHALLER | back to summary |
|---|---|
| private static final Metadata. Marshals status messages for ( By default, the HTTP spec says that header values must be encoded using a strict subset of ASCII (See RFC 7230 section 3.2.6). HTTP/2 HPACK allows use of arbitrary binary headers, but we do not use them for interoperating with existing HTTP/1.1 code. Since the grpc-message is encoded to such a header, it needs to not use forbidden characters. This marshaller works by converting the passed in string into UTF-8, checking to see if each individual byte is an allowable byte, and then either percent encoding or passing it through. When percent encoding, the byte is converted into hexadecimal notation with a '%' prepended. When unmarshalling, bytes are passed through unless they match the "%XX" pattern. If they do match, the unmarshaller attempts to convert them back into their original UTF-8 byte sequence. After the input header bytes are converted into UTF-8 bytes, the new byte array is reinterpretted back as a string. | |
| TEST_EQUALS_FAILURE_PROPERTY | back to summary |
|---|---|
| private static final String TEST_EQUALS_FAILURE_PROPERTY | |
| UNAUTHENTICATED | back to summary |
|---|---|
| public static final Status UNAUTHENTICATED The request does not have valid authentication credentials for the operation. | |
| UNAVAILABLE | back to summary |
|---|---|
| public static final Status UNAVAILABLE The service is currently unavailable. See | |
| UNIMPLEMENTED | back to summary |
|---|---|
| public static final Status UNIMPLEMENTED Operation is not implemented or not supported/enabled in this service. | |
| UNKNOWN | back to summary |
|---|---|
| public static final Status UNKNOWN Unknown error. See | |
| Status | back to summary |
|---|---|
| private Status(Status. | |
| Status | back to summary |
|---|---|
| private Status(Status. | |
| asException | back to summary |
|---|---|
| public StatusException asException() Convert this | |
| asException | back to summary |
|---|---|
| public StatusException asException(Metadata trailers) Same as | |
| asRuntimeException | back to summary |
|---|---|
| public StatusRuntimeException asRuntimeException() Convert this | |
| asRuntimeException | back to summary |
|---|---|
| public StatusRuntimeException asRuntimeException(Metadata trailers) Same as | |
| augmentDescription | back to summary |
|---|---|
| public Status augmentDescription(String additionalDetail) Create a derived instance of | |
| buildStatusList | back to summary |
|---|---|
| private static List | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Equality on Statuses is not well defined. Instead, do comparison based on their Code with
| |
| formatThrowableMessage | back to summary |
|---|---|
| pack-priv static String formatThrowableMessage(Status status) | |
| fromCode | back to summary |
|---|---|
| public static Status fromCode(Status. | |
| fromCodeValue | back to summary |
|---|---|
| public static Status fromCodeValue(int codeValue) | |
| fromCodeValue | back to summary |
|---|---|
| private static Status fromCodeValue(byte[] asciiCodeValue) | |
| fromCodeValueSlow | back to summary |
|---|---|
private static Status fromCodeValueSlow(byte[] asciiCodeValue)
| |
| fromThrowable | back to summary |
|---|---|
| public static Status fromThrowable(Throwable t) Extract an error
| |
| getCause | back to summary |
|---|---|
| public Throwable getCause() The underlying cause of an error. Note that the cause is not transmitted from server to client.
| |
| getCode | back to summary |
|---|---|
| public Status. The canonical status code. | |
| getDescription | back to summary |
|---|---|
| public String getDescription() A description of this status for human consumption.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Hash codes on Statuses are not well defined.
| |
| isOk | back to summary |
|---|---|
| public boolean isOk() Is this status OK, i.e., not an error. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. A string representation of the status useful for debugging.
| |
| trailersFromThrowable | back to summary |
|---|---|
| public static Metadata trailersFromThrowable(Throwable t) Extract an error trailers from the causal chain of a | |
| withCause | back to summary |
|---|---|
| public Status withCause(Throwable cause) Create a derived instance of | |
| withDescription | back to summary |
|---|---|
| public Status withDescription(String description) Create a derived instance of | |
| Modifier and Type | Field and Description |
|---|---|
| public static final Status. | ABORTED
The operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc. See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE. |
| public static final Status. | ALREADY_EXISTS
Some entity that we attempted to create (e.g., file or directory) already exists. |
| public static final Status. | CANCELLED
The operation was cancelled (typically by the caller). |
| public static final Status. | DATA_LOSS
Unrecoverable data loss or corruption. |
| public static final Status. | DEADLINE_EXCEEDED
Deadline expired before operation could complete. |
| public static final Status. | FAILED_PRECONDITION
Operation was rejected because the system is not in a state required for the operation's execution. |
| public static final Status. | INTERNAL
Internal errors. |
| public static final Status. | INVALID_ARGUMENT
Client specified an invalid argument. |
| public static final Status. | NOT_FOUND
Some requested entity (e.g., file or directory) was not found. |
| public static final Status. | OK
The operation completed successfully. |
| public static final Status. | OUT_OF_RANGE
Operation was attempted past the valid range. |
| public static final Status. | PERMISSION_DENIED
The caller does not have permission to execute the specified operation. |
| public static final Status. | RESOURCE_EXHAUSTED
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. |
| public static final Status. | UNAUTHENTICATED
The request does not have valid authentication credentials for the operation. |
| public static final Status. | UNAVAILABLE
The service is currently unavailable. |
| public static final Status. | UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service. |
| public static final Status. | UNKNOWN
Unknown error. |
| private final int | |
| private final byte[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Status | |
| public int | |
| private byte[] | |
| public static Status. | |
| public static Status. |
| ABORTED | back to summary |
|---|---|
| public static final Status. The operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc. See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE. | |
| ALREADY_EXISTS | back to summary |
|---|---|
| public static final Status. Some entity that we attempted to create (e.g., file or directory) already exists. | |
| CANCELLED | back to summary |
|---|---|
| public static final Status. The operation was cancelled (typically by the caller). | |
| DATA_LOSS | back to summary |
|---|---|
| public static final Status. Unrecoverable data loss or corruption. | |
| DEADLINE_EXCEEDED | back to summary |
|---|---|
| public static final Status. Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. | |
| FAILED_PRECONDITION | back to summary |
|---|---|
| public static final Status. Operation was rejected because the system is not in a state required for the operation's execution. For example, directory to be deleted may be non-empty, an rmdir operation is applied to a non-directory, etc. A litmus test that may help a service implementor in deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the client can retry just the failing call. (b) Use ABORTED if the client should retry at a higher-level (e.g., restarting a read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client should not retry until the system state has been explicitly fixed. E.g., if an "rmdir" fails because the directory is non-empty, FAILED_PRECONDITION should be returned since the client should not retry unless they have first fixed up the directory by deleting files from it. | |
| INTERNAL | back to summary |
|---|---|
| public static final Status. Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. | |
| INVALID_ARGUMENT | back to summary |
|---|---|
| public static final Status. Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the system (e.g., a malformed file name). | |
| NOT_FOUND | back to summary |
|---|---|
| public static final Status. Some requested entity (e.g., file or directory) was not found. | |
| OK | back to summary |
|---|---|
| public static final Status. The operation completed successfully. | |
| OUT_OF_RANGE | back to summary |
|---|---|
| public static final Status. Operation was attempted past the valid range. E.g., seeking or reading past end of file. Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state changes. For example, a 32-bit file system will generate INVALID_ARGUMENT if asked to read at an offset that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from an offset past the current file size. There is a fair bit of overlap between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error) when it applies so that callers who are iterating through a space can easily look for an OUT_OF_RANGE error to detect when they are done. | |
| PERMISSION_DENIED | back to summary |
|---|---|
| public static final Status. The caller does not have permission to execute the specified operation. PERMISSION_DENIED must not be used for rejections caused by exhausting some resource (use RESOURCE_EXHAUSTED instead for those errors). PERMISSION_DENIED must not be used if the caller cannot be identified (use UNAUTHENTICATED instead for those errors). | |
| RESOURCE_EXHAUSTED | back to summary |
|---|---|
| public static final Status. Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. | |
| UNAUTHENTICATED | back to summary |
|---|---|
| public static final Status. The request does not have valid authentication credentials for the operation. | |
| UNAVAILABLE | back to summary |
|---|---|
| public static final Status. The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff. Note that it is not always safe to retry non-idempotent operations. See litmus test above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE. | |
| UNIMPLEMENTED | back to summary |
|---|---|
| public static final Status. Operation is not implemented or not supported/enabled in this service. | |
| UNKNOWN | back to summary |
|---|---|
| public static final Status. Unknown error. An example of where this error may be returned is if a Status value received from another address space belongs to an error-space that is not known in this address space. Also errors raised by APIs that do not return enough error information may be converted to this error. | |
| value | back to summary |
|---|---|
| private final int value | |
| valueAscii | back to summary |
|---|---|
private final byte[] valueAscii
| |
| Code | back to summary |
|---|---|
| private Code(int value) | |
| toStatus | back to summary |
|---|---|
| public Status toStatus() Returns a | |
| value | back to summary |
|---|---|
| public int value() The numerical value of the code. | |
| valueAscii | back to summary |
|---|---|
| private byte[] valueAscii() | |
| valueOf | back to summary |
|---|---|
| public static Status. | |
| values | back to summary |
|---|---|
| public static Status. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Status | parseAsciiString(byte[]
value of metadata to parse serialized)Implements io. |
| public byte[] | toAsciiString(Status
to serialize status)Implements io. io..
|
| StatusCodeMarshaller | back to summary |
|---|---|
| private StatusCodeMarshaller() | |
| parseAsciiString | back to summary |
|---|---|
| public Status parseAsciiString(byte[] serialized) Implements io. Doc from io. Parse a serialized metadata value from an ASCII string. | |
| toAsciiString | back to summary |
|---|---|
| public byte[] toAsciiString(Status status) Implements io. Doc from io. Serialize a metadata value to a ASCII string that contains only the characters listed in the
class comment of | |
| Modifier and Type | Field and Description |
|---|---|
| private static final byte[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static boolean | |
| public String | parseAsciiString(byte[]
value of metadata to parse value)Implements io. |
| private static String | |
| public byte[] | toAsciiString(String
to serialize value)Implements io. io..
|
| private static byte[] | toAsciiStringSlow(byte[]
the UTF-8 bytes valueBytes, int The reader index, pointed at the first byte that needs escaping. ri)Percent encode bytes to make them ASCII. |
| HEX | back to summary |
|---|---|
| private static final byte[] HEX | |
| StatusMessageMarshaller | back to summary |
|---|---|
| private StatusMessageMarshaller() | |
| isEscapingChar | back to summary |
|---|---|
| private static boolean isEscapingChar(byte b) | |
| parseAsciiString | back to summary |
|---|---|
| public String parseAsciiString(byte[] value) Implements io. Doc from io. Parse a serialized metadata value from an ASCII string.
| |
| parseAsciiStringSlow | back to summary |
|---|---|
| private static String parseAsciiStringSlow(byte[] value) | |
| toAsciiString | back to summary |
|---|---|
| public byte[] toAsciiString(String value) Implements io. Doc from io. Serialize a metadata value to a ASCII string that contains only the characters listed in the
class comment of | |
| toAsciiStringSlow | back to summary |
|---|---|
| private static byte[] toAsciiStringSlow(byte[] valueBytes, int ri) Percent encode bytes to make them ASCII.
| |