@ -280,6 +280,55 @@ std::string StatusCodeToString(StatusCode code);
// Streams StatusCodeToString(code) to `os`.
// Streams StatusCodeToString(code) to `os`.
std : : ostream & operator < < ( std : : ostream & os , StatusCode code ) ;
std : : ostream & operator < < ( std : : ostream & os , StatusCode code ) ;
// absl::StatusToStringMode
//
// An `absl::StatusToStringMode` is an enumerated type indicating how
// `absl::Status::ToString()` should construct the output string for an non-ok
// status.
enum class StatusToStringMode : int {
// ToString will not contain any extra data (such as payloads). It will only
// contain the error code and message, if any.
kWithNoExtraData = 0 ,
// ToString will contain the payloads.
kWithPayload = 1 < < 0 ,
} ;
// absl::StatusToStringMode is specified as a bitmask type, which means the
// following operations must be provided:
inline constexpr StatusToStringMode operator & ( StatusToStringMode lhs ,
StatusToStringMode rhs ) {
return static_cast < StatusToStringMode > ( static_cast < int > ( lhs ) &
static_cast < int > ( rhs ) ) ;
}
inline constexpr StatusToStringMode operator | ( StatusToStringMode lhs ,
StatusToStringMode rhs ) {
return static_cast < StatusToStringMode > ( static_cast < int > ( lhs ) |
static_cast < int > ( rhs ) ) ;
}
inline constexpr StatusToStringMode operator ^ ( StatusToStringMode lhs ,
StatusToStringMode rhs ) {
return static_cast < StatusToStringMode > ( static_cast < int > ( lhs ) ^
static_cast < int > ( rhs ) ) ;
}
inline constexpr StatusToStringMode operator ~ ( StatusToStringMode arg ) {
return static_cast < StatusToStringMode > ( ~ static_cast < int > ( arg ) ) ;
}
inline StatusToStringMode & operator & = ( StatusToStringMode & lhs ,
StatusToStringMode rhs ) {
lhs = lhs & rhs ;
return lhs ;
}
inline StatusToStringMode & operator | = ( StatusToStringMode & lhs ,
StatusToStringMode rhs ) {
lhs = lhs | rhs ;
return lhs ;
}
inline StatusToStringMode & operator ^ = ( StatusToStringMode & lhs ,
StatusToStringMode rhs ) {
lhs = lhs ^ rhs ;
return lhs ;
}
// absl::Status
// absl::Status
//
//
// The `absl::Status` class is generally used to gracefully handle errors
// The `absl::Status` class is generally used to gracefully handle errors
@ -443,15 +492,17 @@ class ABSL_MUST_USE_RESULT Status final {
// Status::ToString()
// Status::ToString()
//
//
// Returns a combination of the error code name, the message and any
// Returns a string based on the `mode`. By default, it returns combination of
// associated payload messages. This string is designed simply to be human
// the error code name, the message and any associated payload messages. This
// readable and its exact format should not be load bearing. Do not depend on
// string is designed simply to be human readable and its exact format should
// the exact format of the result of `ToString()` which is subject to change.
// not be load bearing. Do not depend on the exact format of the result of
// `ToString()` which is subject to change.
//
//
// The printed code name and the message are generally substrings of the
// The printed code name and the message are generally substrings of the
// result, and the payloads to be printed use the status payload printer
// result, and the payloads to be printed use the status payload printer
// mechanism (which is internal).
// mechanism (which is internal).
std : : string ToString ( ) const ;
std : : string ToString (
StatusToStringMode mode = StatusToStringMode : : kWithPayload ) const ;
// Status::IgnoreError()
// Status::IgnoreError()
//
//
@ -582,8 +633,7 @@ class ABSL_MUST_USE_RESULT Status final {
static uintptr_t PointerToRep ( status_internal : : StatusRep * r ) ;
static uintptr_t PointerToRep ( status_internal : : StatusRep * r ) ;
static status_internal : : StatusRep * RepToPointer ( uintptr_t r ) ;
static status_internal : : StatusRep * RepToPointer ( uintptr_t r ) ;
// Returns string for non-ok Status.
std : : string ToStringSlow ( StatusToStringMode mode ) const ;
std : : string ToStringSlow ( ) const ;
// Status supports two different representations.
// Status supports two different representations.
// - When the low bit is off it is an inlined representation.
// - When the low bit is off it is an inlined representation.
@ -747,8 +797,8 @@ inline bool operator!=(const Status& lhs, const Status& rhs) {
return ! ( lhs = = rhs ) ;
return ! ( lhs = = rhs ) ;
}
}
inline std : : string Status : : ToString ( ) const {
inline std : : string Status : : ToString ( StatusToStringMode mode ) const {
return ok ( ) ? " OK " : ToStringSlow ( ) ;
return ok ( ) ? " OK " : ToStringSlow ( mode ) ;
}
}
inline void Status : : IgnoreError ( ) const {
inline void Status : : IgnoreError ( ) const {