Asylo
Public Member Functions | Static Public Member Functions | List of all members
asylo::Status Class Reference

Status contains information about an error. More...

#include <status.h>

Public Member Functions

 Status ()
 Builds an OK Status in the canonical error space. More...
 
 Status (const error::ErrorSpace *space, int code, absl::string_view message)
 Constructs a Status object containing an error code and message. More...
 
template<typename Enum >
 Status (Enum code, absl::string_view message)
 Constructs a Status object containing an error code and a message. More...
 
 Status (const Status &other)=default
 
 Status (Status &&other)
 
template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
 Status (const StatusT &other)
 Constructs a Status object from StatusT. More...
 
Statusoperator= (const Status &other)=default
 
Statusoperator= (Status &&other)
 
template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
StatusT ToOtherStatus ()
 Copy this object to a status type StatusT. More...
 
int error_code () const
 Gets the integer error code for this object. More...
 
absl::string_view error_message () const
 Gets the string error message for this object. More...
 
const error::ErrorSpaceerror_space () const
 Gets the string error message for this object. More...
 
bool ok () const
 Indicates whether this object is OK (indicates no error). More...
 
std::string ToString () const
 Gets a string representation of this object. More...
 
Status ToCanonical () const
 Gets a copy of this object in the canonical error space. More...
 
error::GoogleError CanonicalCode () const
 Gets the canonical error code for this object's error code. More...
 
void SaveTo (StatusProto *status_proto) const
 Exports the contents of this object into status_proto. More...
 
void RestoreFrom (const StatusProto &status_proto)
 Populates this object using the contents of the given status_proto. More...
 
template<typename Enum >
bool Is (Enum code) const
 Indicates whether this object is the same as code. More...
 

Static Public Member Functions

static Status OkStatus ()
 Constructs an OK status object. More...
 

Detailed Description

Status contains information about an error.

Status contains an error code from some error space and a message string suitable for logging or debugging.

Constructor & Destructor Documentation

◆ Status() [1/6]

asylo::Status::Status ( )

Builds an OK Status in the canonical error space.

◆ Status() [2/6]

asylo::Status::Status ( const error::ErrorSpace space,
int  code,
absl::string_view  message 
)

Constructs a Status object containing an error code and message.

Parameters
spaceThe ErrorSpace this code belongs to.
codeAn integer error code.
messageThe associated error message.

◆ Status() [3/6]

template<typename Enum >
asylo::Status::Status ( Enum  code,
absl::string_view  message 
)
inline

Constructs a Status object containing an error code and a message.

The error space is deduced from code.

Parameters
codeA symbolic error code.
messageThe associated error message.

◆ Status() [4/6]

asylo::Status::Status ( const Status other)
default

◆ Status() [5/6]

asylo::Status::Status ( Status &&  other)

◆ Status() [6/6]

template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
asylo::Status::Status ( const StatusT &  other)
inlineexplicit

Constructs a Status object from StatusT.

StatusT must be a status-type object. I.e.,

  • It must have a two-parameter constructor that takes an enum as its first parameter and a string as its second parameter.
  • It must have non-static error_code(), error_message(), and ok() methods.

This constructor is provided for the convenience of Asylo-SDK consumers utilizing other status types such as ::grpc::Status.

Parameters
otherA status-like object to copy.

Member Function Documentation

◆ CanonicalCode()

error::GoogleError asylo::Status::CanonicalCode ( ) const

Gets the canonical error code for this object's error code.

Returns
A canonical error::GoogleError code.

◆ error_code()

int asylo::Status::error_code ( ) const

Gets the integer error code for this object.

Returns
The associated integer error code.

◆ error_message()

absl::string_view asylo::Status::error_message ( ) const

Gets the string error message for this object.

Returns
The associated error message.

◆ error_space()

const error::ErrorSpace* asylo::Status::error_space ( ) const

Gets the string error message for this object.

Returns
The associated error space.

◆ Is()

template<typename Enum >
bool asylo::Status::Is ( Enum  code) const
inline

Indicates whether this object is the same as code.

This object is considered to be the same as code ifcode` matches both the error code and error space of this object.

Returns
True if this object matches code.

◆ ok()

bool asylo::Status::ok ( ) const

Indicates whether this object is OK (indicates no error).

Returns
True if this object indicates no error.

◆ OkStatus()

static Status asylo::Status::OkStatus ( )
static

Constructs an OK status object.

Returns
A Status indicating no error occurred.

◆ operator=() [1/2]

Status& asylo::Status::operator= ( const Status other)
default

◆ operator=() [2/2]

Status& asylo::Status::operator= ( Status &&  other)

◆ RestoreFrom()

void asylo::Status::RestoreFrom ( const StatusProto &  status_proto)

Populates this object using the contents of the given status_proto.

If the error space given by status_proto.space() is unrecognized, sets the error space to the canonical error space and sets the error code using the value given by status_proto.canonical_code(). If there is no canonical code, sets the error code to error::GoogleError::UNKNOWN. Note that the error message is only set if status_proto represents a non-ok Status.

If the given status_proto is invalid, sets the error code of this object to error::StatusError::INVALID_STATUS_PROTO. A StatusProto is valid if and only if all the following conditions hold:

  • If code() is 0, then canonical_code() is set to 0.
  • If canonical_code() is 0, then code() is set to 0.
  • If the error space is recognized, then canonical_code() is equal to the equivalent canonical code given by the error space.
Parameters
status_protoA protobuf object to set this object from.

◆ SaveTo()

void asylo::Status::SaveTo ( StatusProto *  status_proto) const

Exports the contents of this object into status_proto.

This method sets all fields in status_proto.

Parameters
[out]status_protoA protobuf object to populate.

◆ ToCanonical()

Status asylo::Status::ToCanonical ( ) const

Gets a copy of this object in the canonical error space.

This operation has no effect if the Status object is already in the canonical error space. Otherwise, this translation involves the following:

  • Error code is converted to the equivalent error code in the canonical error space.
  • The new error message is set to the ToString() representation of the old Status object in order to preserve the previous error code information.

◆ ToOtherStatus()

template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
StatusT asylo::Status::ToOtherStatus ( )
inline

Copy this object to a status type StatusT.

The method first converts the asylo::Status object to its canonical form, and then constructs a StatusT from the error code and message fields of the converted object. StatusT must be a status-type object. I.e.,

  • It must have a two-parameter constructor that takes an enum as its first parameter and a string as its second parameter.
  • It must have non-static error_code(), error_message(), and ok() methods.

This operator is provided for the convenience of the Asylo SDK users that utilize other status types, such as ::grpc::Status.

Returns
A status-like object copied from this object.

◆ ToString()

std::string asylo::Status::ToString ( ) const

Gets a string representation of this object.

Gets a string containing the error space name, error code name, and error message if this object is a non-OK Status, or just a string containing the error code name if this object is an OK Status.

Returns
A string representation of this object.

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