Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Data structures & utilities
  5. pw_status
  6. pw::Status Class Reference
pw::Status Class Referencefinal

Overview

Status is a thin, zero-cost abstraction around the pw_Status enum. It initializes to pw::OkStatus() by default and adds ok() and str() methods. Status implicitly converts from pw_Status; use code() to convert a Status to pw_Status.

An OK status is created by the pw::OkStatus() function or by the default Status constructor. Non-OK Status is created with a static member function that corresponds with the status code. Example:

using pw::Status;
Status OperationThatFails() {
// …
return Status::DataLoss();
}
Definition: status.h:200
static constexpr Status DataLoss() noexcept
Definition: status.h:396

A non-OK Status may carry an optional error message created with PW_STATUS_MSG (e.g. Status::NotFound(PW_STATUS_MSG("No such key"))). Messages are discarded at compile time unless PW_STATUS_CFG_MESSAGES enables them. Unlike absl::Status, equality comparisons (== and !=) consider only the status code and ignore messages.

Inheritance diagram for pw::Status:
pw::StatusBase< Status, PW_STATUS_OK >

Public Types

using Code = pw_Status
 
- Public Types inherited from pw::StatusBase< Status, PW_STATUS_OK >
using Code = decltype(kOkCode)
 The underlying status code type.
 

Public Member Functions

constexpr Status (Code code=PW_STATUS_OK) noexcept
 
constexpr Status (Code code, Message message) noexcept
 Creates a status with a PW_STATUS_MSG.
 
constexpr Status (const Status &)=default
 
constexpr Status & operator= (const Status &)=default
 
constexpr Status (Status &&)=default
 
constexpr Status & operator= (Status &&)=default
 
constexpr bool IsCancelled () const noexcept
 
constexpr bool IsUnknown () const noexcept
 
constexpr bool IsInvalidArgument () const noexcept
 
constexpr bool IsDeadlineExceeded () const noexcept
 
constexpr bool IsNotFound () const noexcept
 
constexpr bool IsAlreadyExists () const noexcept
 
constexpr bool IsPermissionDenied () const noexcept
 
constexpr bool IsResourceExhausted () const noexcept
 
constexpr bool IsFailedPrecondition () const noexcept
 
constexpr bool IsAborted () const noexcept
 
constexpr bool IsOutOfRange () const noexcept
 
constexpr bool IsUnimplemented () const noexcept
 
constexpr bool IsInternal () const noexcept
 
constexpr bool IsUnavailable () const noexcept
 
constexpr bool IsDataLoss () const noexcept
 
constexpr bool IsUnauthenticated () const noexcept
 
- Public Member Functions inherited from pw::StatusBase< Status, PW_STATUS_OK >
constexpr bool ok () const noexcept
 Returns true if the status is the OK code.
 
constexpr Code code () const noexcept
 Returns the underlying status code.
 
constexpr bool has_message () const noexcept
 
constexpr Message message () const noexcept
 
constexpr void Update (Status other) noexcept
 
constexpr void IgnoreError () const noexcept
 Ignores any errors, suppressing unused-result warnings.
 
constexpr const char * str () const
 

Static Public Member Functions

static constexpr Status Cancelled () noexcept
 
static constexpr Status Unknown () noexcept
 
static constexpr Status InvalidArgument () noexcept
 
static constexpr Status DeadlineExceeded () noexcept
 
static constexpr Status NotFound () noexcept
 
static constexpr Status AlreadyExists () noexcept
 
static constexpr Status PermissionDenied () noexcept
 
static constexpr Status ResourceExhausted () noexcept
 
static constexpr Status FailedPrecondition () noexcept
 
static constexpr Status Aborted () noexcept
 
static constexpr Status OutOfRange () noexcept
 
static constexpr Status Unimplemented () noexcept
 
static constexpr Status Internal () noexcept
 
static constexpr Status Unavailable () noexcept
 
static constexpr Status DataLoss () noexcept
 
static constexpr Status Unauthenticated () noexcept
 
Factories with a message

Overloads of the functions above that attach a PW_STATUS_MSG.

static constexpr Status Cancelled (Message message) noexcept
 
static constexpr Status Unknown (Message message) noexcept
 
static constexpr Status InvalidArgument (Message message) noexcept
 
static constexpr Status DeadlineExceeded (Message message) noexcept
 
static constexpr Status NotFound (Message message) noexcept
 
static constexpr Status AlreadyExists (Message message) noexcept
 
static constexpr Status PermissionDenied (Message message) noexcept
 
static constexpr Status ResourceExhausted (Message message) noexcept
 
static constexpr Status FailedPrecondition (Message message) noexcept
 
static constexpr Status Aborted (Message message) noexcept
 
static constexpr Status OutOfRange (Message message) noexcept
 
static constexpr Status Unimplemented (Message message) noexcept
 
static constexpr Status Internal (Message message) noexcept
 
static constexpr Status Unavailable (Message message) noexcept
 
static constexpr Status DataLoss (Message message) noexcept
 
static constexpr Status Unauthenticated (Message message) noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from pw::StatusBase< Status, PW_STATUS_OK >
constexpr StatusBase () noexcept=default
 Defaults to kOkCode (ok() == true).
 
constexpr StatusBase (Code code) noexcept
 Explicitly construct from the underlying code.
 
constexpr StatusBase (Code code, Message message) noexcept
 
constexpr StatusBase (const StatusBase &)=default
 
constexpr StatusBase (StatusBase &&)=default
 
constexpr StatusBase & operator= (const StatusBase &)=default
 
constexpr StatusBase & operator= (StatusBase &&)=default
 

Constructor & Destructor Documentation

◆ Status()

constexpr pw::Status::Status ( Code  code = PW_STATUS_OK)
inlineconstexprnoexcept

Statuses are created with a Status::Code.

Precondition
code is a valid status code. Use pw::StatusFromCodeOrUnknown to convert integers that may not be.

Member Function Documentation

◆ Aborted()

static constexpr Status pw::Status::Aborted ( )
inlinestaticconstexprnoexcept

Operation aborted due to e.g. concurrency issue or failed transaction.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (ABORTED). The C++ API for this code is Status::Aborted() (or status.IsAborted()) and the C API is PW_STATUS_ABORTED. See ABORTED for details on interacting with this status code in other languages.

◆ AlreadyExists()

static constexpr Status pw::Status::AlreadyExists ( )
inlinestaticconstexprnoexcept

The entity that the caller requested to create is already present.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (ALREADY_EXISTS). The C++ API for this code is Status::AlreadyExists() (or status.IsAlreadyExists()) and the C API is PW_STATUS_ALREADY_EXISTS. See ALREADY_EXISTS for details on interacting with this status code in other languages.

◆ Cancelled()

static constexpr Status pw::Status::Cancelled ( )
inlinestaticconstexprnoexcept

Operation was cancelled, typically by the caller.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (CANCELLED). The C++ API for this code is Status::Cancelled() (or status.IsCancelled()) and the C API is PW_STATUS_CANCELLED. See CANCELLED for details on interacting with this status code in other languages.

◆ DataLoss()

static constexpr Status pw::Status::DataLoss ( )
inlinestaticconstexprnoexcept

Unrecoverable data loss occurred while completing the requested operation.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (DATA_LOSS). The C++ API for this code is Status::DataLoss() (or status.IsDataLoss()) and the C API is PW_STATUS_DATA_LOSS. See DATA_LOSS for details on interacting with this status code in other languages.

◆ DeadlineExceeded()

static constexpr Status pw::Status::DeadlineExceeded ( )
inlinestaticconstexprnoexcept

Deadline passed before operation completed.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (DEADLINE_EXCEEDED). The C++ API for this code is Status::DeadlineExceeded() (or status.IsDeadlineExceeded()) and the C API is PW_STATUS_DEADLINE_EXCEEDED. See DEADLINE_EXCEEDED for details on interacting with this status code in other languages.

◆ FailedPrecondition()

static constexpr Status pw::Status::FailedPrecondition ( )
inlinestaticconstexprnoexcept

System isn’t in the required state; e.g. deleting a non-empty directory.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (FAILED_PRECONDITION). The C++ API for this code is Status::FailedPrecondition() (or status.IsFailedPrecondition()) and the C API is PW_STATUS_PERMISSION_DENIED. See PERMISSION_DENIED for details on interacting with this status code in other languages.

◆ Internal()

static constexpr Status pw::Status::Internal ( )
inlinestaticconstexprnoexcept

Internal error occurred; e.g. system invariants were violated.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (INTERNAL). The C++ API for this code is Status::Internal() (or status.IsInternal()) and the C API is PW_STATUS_INTERNAL. See INTERNAL for details on interacting with this status code in other languages.

◆ InvalidArgument()

static constexpr Status pw::Status::InvalidArgument ( )
inlinestaticconstexprnoexcept

Argument was malformed; e.g. invalid characters when parsing integer.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (INVALID_ARGUMENT). The C++ API for this code is Status::InvalidArgument() (or status.IsInvalidArgument()) and the C API is PW_STATUS_INVALID_ARGUMENT. See INVALID_ARGUMENT for details on interacting with this status code in other languages.

◆ IsAborted()

constexpr bool pw::Status::IsAborted ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is ABORTED.

◆ IsAlreadyExists()

constexpr bool pw::Status::IsAlreadyExists ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is ALREADY_EXISTS.

◆ IsCancelled()

constexpr bool pw::Status::IsCancelled ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is CANCELLED.

◆ IsDataLoss()

constexpr bool pw::Status::IsDataLoss ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is DATA_LOSS.

◆ IsDeadlineExceeded()

constexpr bool pw::Status::IsDeadlineExceeded ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is DEADLINE_EXCEEDED.

◆ IsFailedPrecondition()

constexpr bool pw::Status::IsFailedPrecondition ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is FAILED_PRECONDITION.

◆ IsInternal()

constexpr bool pw::Status::IsInternal ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is INTERNAL.

◆ IsInvalidArgument()

constexpr bool pw::Status::IsInvalidArgument ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is INVALID_ARGUMENT.

◆ IsNotFound()

constexpr bool pw::Status::IsNotFound ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is NOT_FOUND.

◆ IsOutOfRange()

constexpr bool pw::Status::IsOutOfRange ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is OUT_OF_RANGE.

◆ IsPermissionDenied()

constexpr bool pw::Status::IsPermissionDenied ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is PERMISSION_DENIED.

◆ IsResourceExhausted()

constexpr bool pw::Status::IsResourceExhausted ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is RESOURCE_EXHAUSTED.

◆ IsUnauthenticated()

constexpr bool pw::Status::IsUnauthenticated ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is UNAUTHENTICATED.

◆ IsUnavailable()

constexpr bool pw::Status::IsUnavailable ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is UNAVAILABLE.

◆ IsUnimplemented()

constexpr bool pw::Status::IsUnimplemented ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is UNIMPLEMENTED.

◆ IsUnknown()

constexpr bool pw::Status::IsUnknown ( ) const
inlineconstexprnoexcept
Returns
true if the status of this instance is UNKNOWN.

◆ NotFound()

static constexpr Status pw::Status::NotFound ( )
inlinestaticconstexprnoexcept

The entity that the caller requested (e.g. file or directory) is not found.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (NOT_FOUND). The C++ API for this code is Status::NotFound() (or status.IsNotFound()) and the C API is PW_STATUS_NOT_FOUND. See NOT_FOUND for details on interacting with this status code in other languages.

◆ OutOfRange()

static constexpr Status pw::Status::OutOfRange ( )
inlinestaticconstexprnoexcept

Operation attempted out of range; e.g. seeking past end of file.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (OUT_OF_RANGE). The C++ API for this code is Status::OutOfRange() (or status.IsOutOfRange()) and the C API is PW_STATUS_OUT_OF_RANGE. See OUT_OF_RANGE for details on interacting with this status code in other languages.

◆ PermissionDenied()

static constexpr Status pw::Status::PermissionDenied ( )
inlinestaticconstexprnoexcept

Caller lacks permission to execute action.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (PERMISSION_DENIED). The C++ API for this code is Status::PermissionDenied() (or status.IsPermissionDenied()) and the C API is PW_STATUS_PERMISSION_DENIED. See PERMISSION_DENIED for details on interacting with this status code in other languages.

◆ ResourceExhausted()

static constexpr Status pw::Status::ResourceExhausted ( )
inlinestaticconstexprnoexcept

Insufficient resources to complete operation; e.g. supplied buffer is too small.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (RESOURCE_EXHAUSTED). The C++ API for this code is Status::ResourceExhausted() (or status.IsResourceExhausted()) and the C API is PW_STATUS_RESOURCE_EXHAUSTED. See RESOURCE_EXHAUSTED for details on interacting with this status code in other languages.

◆ Unauthenticated()

static constexpr Status pw::Status::Unauthenticated ( )
inlinestaticconstexprnoexcept

Caller does not have valid authentication credentials for the operation.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (UNAUTHENTICATED). The C++ API for this code is Status::Unauthenticated() (or status.IsUnauthenticated()) and the C API is PW_STATUS_UNAUTHENTICATED. See UNAUTHENTICATED for details on interacting with this status code in other languages.

◆ Unavailable()

static constexpr Status pw::Status::Unavailable ( )
inlinestaticconstexprnoexcept

Requested operation can’t finish now, but may at a later time.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (UNAVAILABLE). The C++ API for this code is Status::Unavailable() (or status.IsUnavailable()) and the C API is PW_STATUS_UNAVAILABLE. See UNAVAILABLE for details on interacting with this status code in other languages.

◆ Unimplemented()

static constexpr Status pw::Status::Unimplemented ( )
inlinestaticconstexprnoexcept

Operation isn’t implemented or supported.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (UNIMPLEMENTED). The C++ API for this code is Status::Unimplemented() (or status.IsUnimplemented()) and the C API is PW_STATUS_UNIMPLEMENTED. See UNIMPLEMENTED for details on interacting with this status code in other languages.

◆ Unknown()

static constexpr Status pw::Status::Unknown ( )
inlinestaticconstexprnoexcept

Unknown error occurred. Avoid this code when possible.

Note
In the Pigweed docs we refer to this code by its generic, canonical name (UNKNOWN). The C++ API for this code is Status::Unknown() (or status.IsUnknown()) and the C API is PW_STATUS_UNKNOWN. See UNKNOWN for details on interacting with this status code in other languages.

The documentation for this class was generated from the following file: