Asylo
Public Member Functions | Friends | 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 Status &other)=default
 
 Status (Status &&other)
 
template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use " "ConvertStatus() from status_helpers.h instead.") explicit Status(const StatusT &other)
 Constructs a Status object from StatusT. More...
 
 Status (const absl::Status &other)
 
Statusoperator= (const Status &other)=default
 
Statusoperator= (Status &&other)
 
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use " "absl::OkStatus() or asylo::OkStatus() instead.") static Status OkStatus()
 Constructs an OK status object. More...
 
template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use " "ConvertStatus() from status_helpers.h instead.") StatusT ToOtherStatus()
 Copy this object to a status type StatusT. More...
 
 operator::absl::Status () const
 
template<class T >
 operator absl::StatusOr< T > () const
 
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use raw_code() " "instead.") int error_code() const
 Gets the integer error code for this object. More...
 
int raw_code () const
 Gets the error code for this object as an int. More...
 
std::string ToString () const
 Gets a string representation of this object. More...
 
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use payloads " "instead of error spaces.") Status ToCanonical() const
 Gets a copy of this object in the canonical error space. More...
 
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use " "StatusToProto() from status_helpers.h instead.") void SaveTo(StatusProto *status_proto) const
 Exports the contents of this object into status_proto. More...
 
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use " "StatusFromProto() from status_helpers.h instead.") void RestoreFrom(const StatusProto &status_proto)
 Populates this object using the contents of the given status_proto. More...
 
template<typename Enum >
 ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use payloads " "instead of error spaces.") bool Is(Enum code) const
 Indicates whether this object is the same as code. More...
 
void SetPayload (absl::string_view type_url, absl::Cord payload)
 Sets the payload for a given type URL, overwriting any previous value. More...
 
bool ErasePayload (absl::string_view type_url)
 Removes the payload associated with a given type URL, if one exists. More...
 
void ForEachPayload (const std::function< void(absl::string_view, const absl::Cord &)> &visitor) const
 Executes a function for each payload in this Status. More...
 
template<typename Enum >
ABSL_DEPRECATED( ABSL_DEPRECATED (Enum code, absl::string_view message)"Deprecated as part of Asylo's absl::Status migration. Use payloads to " "communicate additional error information if needed.") Status(const error
 Constructs a Status object containing an error code and message. More...
 

Friends

bool operator== (const Status &lhs, const Status &rhs)
 

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. Status can also contain any number of (type URL -> byte string) associations called "payloads". These function similarly to payloads in absl::Status.

Constructor & Destructor Documentation

◆ Status() [1/4]

asylo::Status::Status ( )

Builds an OK Status in the canonical error space.

◆ Status() [2/4]

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

◆ Status() [3/4]

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

◆ Status() [4/4]

asylo::Status::Status ( const absl::Status &  other)

Member Function Documentation

◆ ABSL_DEPRECATED() [1/9]

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

Constructs a Status object containing an error code and message.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use payloads to communicate additional error information if needed.
Parameters
spaceThe ErrorSpace this code belongs to.
codeAn integer error code.
messageThe associated error message. Constructs a Status object containing an error code and a message. The error space is deduced from code.
codeA symbolic error code.
messageThe associated error message.

◆ ABSL_DEPRECATED() [2/9]

template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use " "ConvertStatus() from status_helpers.h instead."  ) const &
inline

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.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use ConvertStatus() instead.
Parameters
otherA status-like object to copy.

◆ ABSL_DEPRECATED() [3/9]

asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use " "absl::OkStatus() or asylo::OkStatus() instead."  )

Constructs an OK status object.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use absl::OkStatus() or asylo::OkStatus() instead.
Returns
A Status indicating no error occurred.

◆ ABSL_DEPRECATED() [4/9]

template<typename StatusT , typename E = typename absl::enable_if_t< status_internal::status_type_traits<StatusT>::is_status>>
asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use " "ConvertStatus() from status_helpers.h instead."  )
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.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use ConvertStatus() instead.
Returns
A status-like object copied from this object.

◆ ABSL_DEPRECATED() [5/9]

asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use raw_code() " "instead."  ) const

Gets the integer error code for this object.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use raw_code() instead.
Returns
The associated integer error code.

◆ ABSL_DEPRECATED() [6/9]

asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use payloads " "instead of error spaces."  ) 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, excluding any payloads, in order to preserve the previous error code information.
Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use payloads instead of error spaces.

◆ ABSL_DEPRECATED() [7/9]

asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use " "StatusToProto() from status_helpers.h instead."  ) const

Exports the contents of this object into status_proto.

This method sets the space and canonical_code fields in status_proto even if this object is in the canonical error space.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use StatusToProto() instead.
Parameters
[out]status_protoA protobuf object to populate.

◆ ABSL_DEPRECATED() [8/9]

asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use " "StatusFromProto() from status_helpers.h instead."  ) const &

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 absl::StatusCode::kUnknown. Note that the error message is only set if status_proto represents a non-ok Status.

If the given status_proto is invalid, sets an appropriate error code and message. 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.
Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use StatusFromProto() instead.
Parameters
status_protoA protobuf object to set this object from.

◆ ABSL_DEPRECATED() [9/9]

template<typename Enum >
asylo::Status::ABSL_DEPRECATED ( "Deprecated as part of Asylo's absl::Status migration. Use payloads " "instead of error spaces."  ) 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.

Deprecated:
Deprecated as part of Asylo's absl::Status migration. Use payloads instead of error spaces.
Returns
True if this object matches code.

◆ ErasePayload()

bool asylo::Status::ErasePayload ( absl::string_view  type_url)

Removes the payload associated with a given type URL, if one exists.

Parameters
type_urlThe type URL to clear.
Returns
True if a payload was removed, false otherwise.

◆ ForEachPayload()

void asylo::Status::ForEachPayload ( const std::function< void(absl::string_view, const absl::Cord &)> &  visitor) const

Executes a function for each payload in this Status.

Specifically, calls visitor exactly once on each payload contained in this Status. The order in which the payloads are visited is unspecified and may change between calls to ForEachPayload().

Modifying the Status object from within visitor is disallowed and may result in undefined behavior.

Parameters
visitorA function to call on each type URL and associated payload.

◆ operator absl::StatusOr< T >()

template<class T >
asylo::Status::operator absl::StatusOr< T > ( ) const
inline

◆ operator::absl::Status()

asylo::Status::operator::absl::Status ( ) const

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ raw_code()

int asylo::Status::raw_code ( ) const

Gets the error code for this object as an int.

Returns
The associated integer error code.

◆ SetPayload()

void asylo::Status::SetPayload ( absl::string_view  type_url,
absl::Cord  payload 
)

Sets the payload for a given type URL, overwriting any previous value.

Parameters
type_urlA type URL.
payloadThe payload to assoicate with type_url.

◆ 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.

The string also contains a list of payloads contained in this Status.

Returns
A string representation of this object.

Friends And Related Function Documentation

◆ operator==

bool operator== ( const Status lhs,
const Status rhs 
)
friend

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