Reference#
pw_status: Exception-free error propagation for embedded
Status codes#
-
enumerator OK = 0#
OKindicates that the operation completede successfully. It is typical to check for this value before proceeding on any given call across an API or RPC boundary. To check this value, use theok()member function rather than inspecting the raw code.C++
C
Python / Java / TypeScript
Status.OKRust
Ok(val)
-
enumerator CANCELLED = 1#
CANCELLEDindicates the operation was cancelled, typically by the caller.C++
C
Python / Java / TypeScript
Status.CANCELLEDRust
Error::Cancelled
-
enumerator UNKNOWN = 2#
UNKNOWNindicates an unknown error occurred. In general, more specific errors should be raised, if possible. Errors raised by APIs that do not return enough error information may be converted to this error.C++
C
Python / Java / TypeScript
Status.UNKNOWNRust
Error::Unknown
-
enumerator INVALID_ARGUMENT = 3#
INVALID_ARGUMENTindicates the caller specified an invalid argument, such as a malformed filename. Note that use of such errors should be narrowly limited to indicate the invalid nature of the arguments themselves. Errors with validly formed arguments that may cause errors with the state of the receiving system should be denoted withFAILED_PRECONDITIONinstead.C++
C
Python / Java / TypeScript
Status.INVALID_ARGUMENTRust
Error::InvalidArgument
-
enumerator DEADLINE_EXCEEDED = 4#
DEADLINE_EXCEEDEDindicates a deadline expired before the operation could complete. For operations that may change state within a 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.C++
C
Python / Java / TypeScript
Status.DEADLINE_EXCEEDEDRust
Error::DeadlineExceeded
-
enumerator NOT_FOUND = 5#
NOT_FOUNDindicates some requested entity (such as a file or directory) was not found.NOT_FOUNDis useful if a request should be denied for an entire class of users, such as during a gradual feature rollout or undocumented allowlist. If a request should be denied for specific sets of users, such as through user-based access control, usePERMISSION_DENIEDinstead.C++
C
Python / Java / TypeScript
Status.NOT_FOUNDRust
Error::NotFound
-
enumerator ALREADY_EXISTS = 6#
ALREADY_EXISTSindicates that the entity a caller attempted to create (such as a file or directory) is already present.C++
C
Python / Java / TypeScript
Status.ALREADY_EXISTSRust
Error::AlreadyExists
-
enumerator PERMISSION_DENIED = 7#
PERMISSION_DENIEDindicates that the caller does not have permission to execute the specified operation. Note that this error is different than an error due to an unauthenticated user. This error code does not imply the request is valid or the requested entity exists or satisfies any other pre-conditions.PERMISSION_DENIEDmust not be used for rejections caused by exhausting some resource. Instead, useRESOURCE_EXHAUSTEDfor those errors.PERMISSION_DENIEDmust not be used if the caller cannot be identified. Instead, useUNAUTHENTICATEDfor those errors.C++
C
Python / Java / TypeScript
Status.PERMISSION_DENIEDRust
Error::PermissionDenied
-
enumerator RESOURCE_EXHAUSTED = 8#
RESOURCE_EXHAUSTEDindicates some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.C++
C
Python / Java / TypeScript
Status.RESOURCE_EXHAUSTEDRust
Error::ResourceExhausted
-
enumerator FAILED_PRECONDITION = 9#
FAILED_PRECONDITIONindicates that the operation was rejected because the system is not in a state required for the operation’s execution. For example, a directory to be deleted may be non-empty, anrmdiroperation is applied to a non-directory, etc.Some guidelines that may help a service implementer in deciding between
FAILED_PRECONDITION,ABORTED, andUNAVAILABLE:Use
UNAVAILABLEif the client can retry just the failing call.Use
ABORTEDif the client should retry at a higher transaction level (such as when a client-specified test-and-set fails, indicating the client should restart a read-modify-write sequence).Use
FAILED_PRECONDITIONif the client should not retry until the system state has been explicitly fixed. For example, if armdirfails because the directory is non-empty,FAILED_PRECONDITIONshould be returned since the client should not retry unless the files are deleted from the directory.
C++
C
Python / Java / TypeScript
Status.FAILED_PRECONDITIONRust
Error::FailedPrecondition
-
enumerator ABORTED = 10#
ABORTEDindicates the operation was aborted, typically due to a concurrency issue such as a sequencer check failure or a failed transaction.See the guidelines above for deciding between
FAILED_PRECONDITION,ABORTED, andUNAVAILABLE.C++
C
Python / Java / TypeScript
Status.ABORTEDRust
Error::Aborted
-
enumerator OUT_OF_RANGE = 11#
OUT_OF_RANGEindicates the operation was attempted past the valid range, such as seeking or reading past an 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 generateINVALID_ARGUMENTif asked to read at an offset that is not in the range [0,2^32-1], but it will generateOUT_OF_RANGEif asked to read from an offset past the current file size.There is a fair bit of overlap between
FAILED_PRECONDITIONandOUT_OF_RANGE. UseOUT_OF_RANGE(the more specific error) when it applies so that callers who are iterating through a space can easily look for anOUT_OF_RANGEerror to detect when they are done.C++
C
Python / Java / TypeScript
Status.OUT_OF_RANGERust
Error::OutOfRange
-
enumerator UNIMPLEMENTED = 12#
UNIMPLEMENTEDindicates the operation is not implemented or supported in this service. In this case, the operation should not be re-attempted.C++
C
Python / Java / TypeScript
Status.UNIMPLEMENTEDRust
Error::Unimplemented
-
enumerator INTERNAL = 13#
INTERNALindicates an internal error has occurred and some invariants expected by the underlying system have not been satisfied. This error code is reserved for serious errors.C++
C
Python / Java / TypeScript
Status.INTERNALRust
Error::Internal
-
enumerator UNAVAILABLE = 14#
UNAVAILABLEindicates the service is currently unavailable and that this is most likely a transient condition. An error such as this can be corrected by retrying with a backoff scheme. Note that it is not always safe to retry non-idempotent operations.See the guidelines above for deciding between
FAILED_PRECONDITION,ABORTED, andUNAVAILABLE.C++
C
Python / Java / TypeScript
Status.UNAVAILABLERust
Error::Unavailable
-
enumerator DATA_LOSS = 15#
DATA_LOSSindicates that unrecoverable data loss or corruption has occurred. As this error is serious, proper alerting should be attached to errors such as this.C++
C
Python / Java / TypeScript
Status.DATA_LOSSRust
Error::DataLoss
-
enumerator UNAUTHENTICATED = 16#
UNAUTHENTICATEDindicates that the request does not have valid authentication credentials for the operation. Correct the authentication and try again.C++
C
Python / Java / TypeScript
Status.UNAUTHENTICATEDRust
Error::Unauthenticated
C++ API#
Moved: pw_status
Unused result warnings#
If the PW_STATUS_CFG_CHECK_IF_USED option is enabled,
pw::Status objects returned from function calls must be used or it
is a compilation error. To silence these warnings call IgnoreError() on the
returned status object.
PW_STATUS_CFG_CHECK_IF_USED defaults to false in GN and CMake,
but true in Bazel. Pigweed compiles with this option enabled, but projects
that use Pigweed will need to be updated to compile with this option. After all
projects have migrated, unused result warnings will be enabled unconditionally.
C API#
pw_status provides the C-compatible pw_Status enum for the status
codes. For ease of use, pw::Status implicitly converts to and from
pw_Status. However, the pw_Status enum should never be used
in C++; instead use the pw::Status class.
Rust API#
pw_status’s Rust API is documented in our
rustdoc API docs.