Package io.grpc
Class Status
java.lang.Object
io.grpc.Status
Defines the status of an operation by providing a standard
Status.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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StatusThe operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc.static final StatusSome entity that we attempted to create (e.g., file or directory) already exists.static final StatusThe operation was cancelled (typically by the caller).static final StatusUnrecoverable data loss or corruption.static final StatusDeadline expired before operation could complete.static final StatusOperation was rejected because the system is not in a state required for the operation's execution.static final StatusInternal errors.static final StatusClient specified an invalid argument.static final StatusSome requested entity (e.g., file or directory) was not found.static final StatusThe operation completed successfully.static final StatusOperation was attempted past the valid range.static final StatusThe caller does not have permission to execute the specified operation.static final StatusSome resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.static final StatusThe request does not have valid authentication credentials for the operation.static final StatusThe service is currently unavailable.static final StatusOperation is not implemented or not supported/enabled in this service.static final StatusUnknown error. -
Method Summary
Modifier and TypeMethodDescriptionasException(Metadata trailers) Same asasException()but includes the provided trailers in the returned exception.Convert thisStatusto aRuntimeException.asRuntimeException(Metadata trailers) Same asasRuntimeException()but includes the provided trailers in the returned exception.augmentDescription(String additionalDetail) Create a derived instance ofStatusaugmenting the current description with additional detail.booleanEquality on Statuses is not well defined.static StatusfromCode(Status.Code code) Return aStatusgiven a canonical errorStatus.Codeobject.static StatusfromCodeValue(int codeValue) Return aStatusgiven a canonical errorStatus.Codevalue.static StatusgetCause()The underlying cause of an error.getCode()The canonical status code.A description of this status for human consumption.inthashCode()Hash codes on Statuses are not well defined.booleanisOk()Is this status OK, i.e., not an error.toString()A string representation of the status useful for debugging.static MetadataExtract an error trailers from the causal chain of aThrowable.Create a derived instance ofStatuswith the given cause.withDescription(String description) Create a derived instance ofStatuswith the given description.
-
Field Details
-
OK
The operation completed successfully. -
CANCELLED
The operation was cancelled (typically by the caller). -
UNKNOWN
Unknown error. SeeStatus.Code.UNKNOWN. -
INVALID_ARGUMENT
Client specified an invalid argument. SeeStatus.Code.INVALID_ARGUMENT. -
DEADLINE_EXCEEDED
Deadline expired before operation could complete. SeeStatus.Code.DEADLINE_EXCEEDED. -
NOT_FOUND
Some requested entity (e.g., file or directory) was not found. -
ALREADY_EXISTS
Some entity that we attempted to create (e.g., file or directory) already exists. -
PERMISSION_DENIED
The caller does not have permission to execute the specified operation. SeeStatus.Code.PERMISSION_DENIED. -
UNAUTHENTICATED
The request does not have valid authentication credentials for the operation. -
RESOURCE_EXHAUSTED
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. -
FAILED_PRECONDITION
Operation was rejected because the system is not in a state required for the operation's execution. SeeStatus.Code.FAILED_PRECONDITION. -
ABORTED
The operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc. SeeStatus.Code.ABORTED. -
OUT_OF_RANGE
Operation was attempted past the valid range. SeeStatus.Code.OUT_OF_RANGE. -
UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service. -
INTERNAL
Internal errors. SeeStatus.Code.INTERNAL. -
UNAVAILABLE
The service is currently unavailable. SeeStatus.Code.UNAVAILABLE. -
DATA_LOSS
Unrecoverable data loss or corruption.
-
-
Method Details
-
fromCodeValue
Return aStatusgiven a canonical errorStatus.Codevalue. -
fromCode
Return aStatusgiven a canonical errorStatus.Codeobject. -
fromThrowable
Extract an errorStatusfrom the causal chain of aThrowable. If no status can be found, a status is created withStatus.Code.UNKNOWNas its code andtas its cause.- Returns:
- non-
nullstatus
-
trailersFromThrowable
Extract an error trailers from the causal chain of aThrowable.- Returns:
- the trailers or
nullif not found.
-
withCause
Create a derived instance ofStatuswith the given cause. However, the cause is not transmitted from server to client. -
withDescription
Create a derived instance ofStatuswith the given description. Leading and trailing whitespace may be removed; this may change in the future. -
augmentDescription
Create a derived instance ofStatusaugmenting the current description with additional detail. Leading and trailing whitespace may be removed; this may change in the future. -
getCode
The canonical status code. -
getDescription
A description of this status for human consumption. -
getCause
The underlying cause of an error. Note that the cause is not transmitted from server to client. -
isOk
public boolean isOk()Is this status OK, i.e., not an error. -
asRuntimeException
Convert thisStatusto aRuntimeException. UsefromThrowable(java.lang.Throwable)to recover thisStatusinstance when the returned exception is in the causal chain. -
asRuntimeException
Same asasRuntimeException()but includes the provided trailers in the returned exception. -
asException
Convert thisStatusto anException. UsefromThrowable(java.lang.Throwable)to recover thisStatusinstance when the returned exception is in the causal chain. -
asException
Same asasException()but includes the provided trailers in the returned exception. -
toString
A string representation of the status useful for debugging. -
equals
Equality on Statuses is not well defined. Instead, do comparison based on their Code withgetCode(). The description and cause of the Status are unlikely to be stable, and additional fields may be added to Status in the future. -
hashCode
public int hashCode()Hash codes on Statuses are not well defined.
-