Skip to main content

Error

Struct Error 

Source
pub struct Error { /* private fields */ }
Expand description

The error every SDK call can answer with: SPEC §6’s record, read through accessors.

It is three pointers wide — the record lives behind a box, beside an optional boxed cause — so a Result<T, Error> stays small on the success path.

Implementations§

Source§

impl Error

Source

pub fn new(code: ErrorCode, message: impl Into<String>) -> Error

An error with a code and a message. The message is bounded to MAX_ERROR_MESSAGE_LENGTH here, so every construction site is bounded.

Source

pub fn network_timeout(source: impl Error + Send + Sync + 'static) -> Error

A transport failure that was a timeout: the request was sent and no answer arrived in the transport’s own time. Retryable, and told apart from other transport failures by Error::is_timeout where a loop treats the two differently (SPEC §16).

Source

pub fn usage(message: impl Into<String>) -> Error

A client-side misuse.

Source

pub fn network(source: impl Error + Send + Sync + 'static) -> Error

A transport failure: no connection, a timeout, a broken stream. Retryable.

Source

pub fn network_at(origin: &str) -> Error

A transport failure whose cause is not chained, for a request whose URL carries a credential (SPEC §9): only the origin is named.

Source

pub fn malformed_response(detail: impl Into<String>) -> Error

A successful status whose body could not be read as the type the operation declares: statusless, non-retryable api_error (SPEC §6).

Source

pub fn response_too_large(limit: usize) -> Error

A body the client refused to read past its cap.

Source

pub fn deadline_exceeded(after: Duration) -> Error

The operation deadline passed before the call finished.

Source

pub fn from_response( status: StatusCode, headers: &HeaderMap, body: &[u8], ) -> Error

Maps a non-2xx response onto SPEC §6’s status table, parses the body per its Error Body Parsing and field-keyed algorithms, and reads Retry-After and X-Request-Id.

Source

pub fn with_hint(self, hint: impl Into<String>) -> Error

The same error with a hint, cut to the message cap like the message itself: a transport’s rendering of its own failure is not bounded by anyone else.

Source

pub fn with_status(self, status: u16) -> Error

The same error carrying an HTTP status.

Source

pub fn with_request_id(self, request_id: impl Into<String>) -> Error

The same error carrying a request id, bounded like the message: the header is the server’s to fill.

Source

pub fn with_retry_after(self, seconds: u32) -> Error

The same error carrying the seconds a Retry-After header named.

Source

pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Error

The same error with a cause.

Source

pub fn retryable(self, retryable: bool) -> Error

The same error, retryable or not.

Source

pub fn code(&self) -> ErrorCode

The categorical code.

Source

pub fn message(&self) -> &str

The human-readable description, at most MAX_ERROR_MESSAGE_LENGTH characters.

Source

pub fn hint(&self) -> Option<&str>

Resolution guidance, when there is any.

Source

pub fn http_status(&self) -> Option<u16>

The HTTP status that caused the error, when one did.

Source

pub fn is_retryable(&self) -> bool

Whether the operation can be retried.

Source

pub fn retry_after(&self) -> Option<u32>

The seconds Retry-After named, parsed per SPEC §6, at whatever status carried it.

Source

pub fn request_id(&self) -> Option<&str>

X-Request-Id, when the response carried one.

Source

pub fn field_errors(&self) -> Option<&BTreeMap<String, Vec<String>>>

The structured 400/422 field messages, raw and untruncated. Row-keyed bodies land here keyed by email address, then index, then position.

Source

pub fn confirmation_people( &self, ) -> Option<&[TemplateLibraryConfirmationPerson]>

The people a template-library copy needs confirmed, when a 422 named them.

Source

pub fn exit_code(&self) -> i32

The process exit status a command should end with.

Source

pub fn body(&self) -> Option<&[u8]>

The failure body, up to MAX_ERROR_BODY_BYTES, when the server sent one.

Source

pub fn is_response_too_large(&self) -> bool

The answer was longer than the client will hold.

Source

pub fn is_deadline_exceeded(&self) -> bool

The operation deadline passed.

Source

pub fn is_timeout(&self) -> bool

The transport reported a timeout.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ErrorCode> for Error

Source§

fn from(code: ErrorCode) -> Error

Converts to this type from the input type.
Source§

impl From<RecordingSummaryError> for Error

Source§

fn from(reason: RecordingSummaryError) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Forget for Error

§

impl Freeze for Error

§

impl Move for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more