Skip to main content

Error

Struct Error 

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

The error every SDK call can answer with.

Implementations§

Source§

impl Error

Source

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

An error of a category, with a message.

Source

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

The call was built wrong.

Source

pub fn usage_with_hint( message: impl Into<String>, hint: impl Into<String>, ) -> Error

The call was built wrong, and here is what to do about it.

Source

pub fn not_found(resource: &str, identifier: impl Display) -> Error

A record that is not there.

Source

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

Credentials missing or refused.

Source

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

Access denied.

Source

pub fn forbidden_scope() -> Error

Access denied for want of scope, as a write answered 403 usually is.

Source

pub fn rate_limit(retry_after: Option<u64>) -> Error

The rate-limit error a caller raises for itself, worded the way the other SDKs word theirs: “Rate limited”. A 429 that came back from Fizzy reads “rate limited - try again later” instead — see Error::from_response.

Source

pub fn rate_limited() -> Error

The client’s own rate limiter refused a call, so nothing was sent.

Source

pub fn circuit_open() -> Error

The scope’s circuit breaker is open, so the SDK refused the call itself.

Source

pub fn bulkhead_full() -> Error

The scope already has as many calls in flight as its bulkhead allows.

Source

pub fn cancelled() -> Error

The caller dropped the future before it finished — a tokio::time::timeout that expired, a select! that took another branch. Nobody is waiting for this error: it is what the operation hooks are told the call ended as, so the bookkeeping every layer keeps per operation is closed out rather than left open.

It is a ErrorCode::Network because that is what a call that never got an answer is. It is not retryable: there is nobody left to answer. It does not count against the circuit breaker — a deadline the caller chose says nothing about Fizzy.

Source

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

No answer came back.

Source

pub fn api(status: u16, message: impl Into<String>) -> Error

The server answered with a failure.

Source

pub fn response_too_large(limit: usize, method: &Method, path: &str) -> Error

A body the client refused to read, because reading it whole is what the caller would have gone on to do. It carries no HTTP status of its own: the answer never arrived in full, so there is nothing to report about it but the refusal.

Source

pub fn validation(messages: &[String]) -> Error

The messages the server itself produced, joined. With none of them the error still says something: “validation error”.

Source

pub fn ambiguous(resource: &str, matches: &[String]) -> Error

A name that matched more than one record. Up to five matches are named in the hint; beyond that the only useful advice is to narrow the search.

Source

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

Wraps an error from outside the SDK as an API error that reads the way the original did, for the callers that have to answer with this type and nothing better fits.

Source

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

Maps a non-2xx response onto the SDK’s error vocabulary. The hint carries whatever message the server put in the body, when it sent one, and the body itself is kept on the error for a caller that needs more of it than a hint — see Error::body.

Source

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

Adds advice.

Source

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

Records the HTTP status.

Source

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

Records the server’s request id.

Source

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

Records what caused this.

Source

pub fn retryable(self) -> Error

Marks the call as worth resending.

Source

pub fn code(&self) -> ErrorCode

The category.

Source

pub fn is_code(&self, code: ErrorCode) -> bool

Whether the error is of this category.

Source

pub fn exit_code(&self) -> i32

The process exit status a command should end with for this error.

Source

pub fn message(&self) -> &str

What went wrong.

Source

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

What to do about it, when there is advice.

Source

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

The HTTP status, when the server answered.

Source

pub fn is_retryable(&self) -> bool

Whether resending would be worth trying.

Source

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

The server’s X-Request-Id, when it sent one.

Source

pub fn refusal(&self) -> Option<Refusal>

Which of the SDK’s own layers turned the call away, when one did.

Source

pub fn is_cancelled(&self) -> bool

The caller gave up on the call before it finished. See Error::cancelled.

Source

pub fn is_response_too_large(&self) -> bool

The answer was longer than the client will hold in memory, whether that refusal is the error itself or sits behind the status the answer carried.

Source

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

What Fizzy answered the failure with, up to MAX_ERROR_BODY_BYTES. A 422 describes the fields it objected to in the body, and this is where that account is kept. It is None when the answer carried no body, when the SDK raised the error itself, and when the body was too long to read.

Source

pub fn body_json<T: DeserializeOwned>(&self) -> Option<T>

The failure body read as T, or None when there is no body or it does not read as one.

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, f: &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

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<Error> for Error

Source§

fn from(error: Error) -> Error

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(error: ParseError) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze 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