class Status

Defined at line 219 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

|Status| represents the result of an operation.

If the operation was successful:

- `ok()` returns true.

- `status()` returns ZX_OK.

- `reason()` should not be used.

If the operation failed:

- `ok()` returns false.

- `status()` contains a non-OK status code specific to the failed operation.

- `reason()` describes the operation which failed.

|Status| may be piped to an output stream (`std::cerr`, `FX_LOGS`, ...) to

print a human-readable description for debugging purposes.

Public Methods

Status Canceled (fidl::UnbindInfo cause)

Constructs a result indicating that the operation is being canceled due to

a problem somewhere else that forced the endpoint to be unbound. For

example, we'd like to inform the user that their FIDL call "B" now has to

be canceled due to a fatal error in FIDL call "A".

Defined at line 119 of file ../../sdk/lib/fidl/cpp/wire/status.cc

std::string FormatDescription ()

Renders a full description of the success or error.

It is more specific than |reason| alone e.g. if an encoding error was

encountered, it would contain a string description of the specific encoding

problem.

If a logging API supports output streams (`

<

<

` operators), piping the

|Status| to the log via `

<

<

` is more efficient than calling this function.

Defined at line 126 of file ../../sdk/lib/fidl/cpp/wire/status.cc

const char * lossy_description ()

Returns a lossy description of the error. The returned |const char*| has

static lifetime, hence may be retained or passed around. If the result is a

success, returns |nullptr|.

Because of this constraint, the bindings will attempt to pick a static

string that best represents the error, sometimes losing information. As

such, this method should only be used when interfacing with C APIs that are

unable to take a string or output stream.

Defined at line 132 of file ../../sdk/lib/fidl/cpp/wire/status.cc

void Status ()

Defined at line 221 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

void ~Status ()

Defined at line 222 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status Ok ()

Constructs a result representing a success.

Defined at line 225 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status Unbound ()

Constructs a result indicating that the operation cannot proceed

because the corresponding endpoint has been unbound from the dispatcher

(applies to both client and server).

Defined at line 230 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status PendingTwoWayCallPreventsUnbind ()

Defined at line 234 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status UnknownOrdinal ()

Constructs a result indicating that the operation cannot proceed

because a unknown message was received. Specifically, the method or event

ordinal is not recognized by the binding.

Defined at line 247 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status PeerClosedWhileReading (zx_status_t status)

Defined at line 252 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status TransportError (zx_status_t status, const char * error_message)

Constructs a transport error with |status| and optional |error_message|.

|status| must not be |ZX_OK|.

Defined at line 258 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status UnknownMethod ()

Constructs a status for an unknown interaction.

Defined at line 274 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status EncodeError (zx_status_t status, const char * error_message)

Defined at line 279 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status DecodeError (zx_status_t status, const char * error_message)

Defined at line 283 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status UnexpectedMessage (zx_status_t status, const char * error_message)

Defined at line 287 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

void Status (const Status & result)

Defined at line 292 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Status & operator= (const Status & result)

Defined at line 293 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

zx_status_t status ()

Status associated with the reason. See documentation on |fidl::Reason|

for how to interpret the status.

Generally, logging this status alone wouldn't be very useful, since its

interpretation is dependent on the reason.

Prefer logging |error| or via |FormatDescription|.

Defined at line 301 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

const char * status_string ()

Returns the string representation of the status value.

Defined at line 309 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

::fidl::Reason reason ()

A high-level reason for the failure.

Generally, logging this value alone wouldn't be the most convenient for

debugging, since it requires developers to check back to the enum.

Prefer logging |error| or via |FormatDescription|.

Defined at line 316 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

std::optional< ::fidl::Reason> underlying_reason ()

A high-level reason for the underlying failure. An underlying reason

is present if and only if |reason| is |Reason::kCanceledDueToOtherError|,

that is, the operation was canceled due to a previous fatal error.

Generally, logging this value alone wouldn't be the most convenient for

debugging, since it requires developers to check back to the enum.

Prefer logging |error| or via |FormatDescription|.

Defined at line 328 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

bool is_peer_closed ()

Returns if the operation failed because the peer endpoint was closed while

the bindings runtime was reading, or waiting to read a message.

If this error happens on the client side and an epitaph was received,

|status| contains the value of the epitaph.

This error is of interest since some protocol users may consider the peer

going away to be part of its normal operation, while others might not.

Note that if a FIDL operation only involves writing to a transport (e.g.

one way calls), then peer closed errors are hidden, to discourage race

conditions.

Defined at line 348 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

bool is_dispatcher_shutdown ()

Returns if the operation failed because the async dispatcher is shutting

down.

Defined at line 352 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

bool is_canceled ()

Returns if the operation failed because it was canceled (i.e. the user or

another unrelated error tore down the binding in the meantime).

Defined at line 358 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

bool ok ()

If the operation was successful.

Defined at line 385 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

const Status & error ()

If the operation failed, returns information about the error.

This is meant be used by subclasses to accommodate a usage style that is

similar to |fit::result| types:

fidl::WireResult bar = fidl::WireCall(foo_client_end)->GetBar();

if (!bar.ok()) {

FX_LOGS(ERROR)

<

<

"GetBar failed: "

<

<

bar.error();

}

Defined at line 397 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Protected Methods

const char * reason_description ()

A human readable description of |reason|.

Defined at line 141 of file ../../sdk/lib/fidl/cpp/wire/status.cc

const char * underlying_reason_description ()

A human readable description of |underlying_reason|.

Defined at line 143 of file ../../sdk/lib/fidl/cpp/wire/status.cc

size_t FormatImpl (char * destination, size_t length, bool from_unbind_info)

Renders the description into a buffer |destination| that is of size

|length|. The description will cut off at `length - 1`. It inserts a

trailing NUL.

|from_unbind_info| should be true iff this is invoked by |UnbindInfo|.

Returns how many bytes were written, not counting the NUL.

Defined at line 148 of file ../../sdk/lib/fidl/cpp/wire/status.cc

void SetStatus (const Status & other)

Defined at line 403 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

const char ** error_address ()

Returns a pointer to populate additional error message.

Defined at line 406 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/status.h

Friends

class formatter
class DisplayError
std::ostream & Status (std::ostream & ostream, const Status & result)
class UnbindInfo