Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error<E> { RequestConstruction(RequestError), Transport(TransportError), Timeout(TimeoutKind), Protocol(ProtocolError), Redirect(RedirectError), Api(ResponseValue<E>), UnexpectedStatus { status: StatusCode, headers: HeaderMap, body: Bytes, }, Decode { status: StatusCode, headers: HeaderMap, path: String, body: Bytes, truncated: bool, }, InterruptedBody(TransportError), }
Expand description

The closed error taxonomy shared by every spargen-generated client. E is the operation’s typed error body (an enum when several error statuses are documented).

Nine variants are constructed; taxonomy class #10 (cancellation) is a documented drop-safety guarantee, not a variant (see the crate docs). Every variant implements std::error::Error with full source chains, and Debug never leaks secrets.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

RequestConstruction(RequestError)

#1 — invalid base URL, or parameter/body serialization failure (near-impossible by construction).

§

Transport(TransportError)

#2 — DNS failure, connection refused/reset, TLS handshake or certificate error.

§

Timeout(TimeoutKind)

#3 — connect vs total-request timeout (as configured on the injected client).

§

Protocol(ProtocolError)

#4 — malformed HTTP or decompression failure.

§

Redirect(RedirectError)

#5 — redirect-policy exhaustion (per the injected client’s policy).

§

Api(ResponseValue<E>)

#6 — a documented non-success status parsed into the operation’s typed error body.

§

UnexpectedStatus

#7 — an undocumented status; the raw body is preserved for forensics.

Fields

§status: StatusCode

The response status.

§headers: HeaderMap

The response headers.

§body: Bytes

The raw response body.

§

Decode

#8 — the response body failed to deserialize; retains the response status and headers (so the status and a request-ID header survive a body the client cannot read), the serde error path, and the (capped) raw body. For a streamed item they are those of the response that carried the malformed frame.

Fields

§status: StatusCode

The response status.

§headers: HeaderMap

The response headers.

§path: String

The serde deserialization error path.

§body: Bytes

The retained raw body (up to the configured cap).

§truncated: bool

Whether the retained body was truncated at the cap.

§

InterruptedBody(TransportError)

#9 — the connection dropped mid-stream on a streamed response.

Implementations§

Source§

impl<E> Error<E>

Source

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

Build a request-construction error from any owned error value.

Source

pub fn request_message(message: impl Into<String>) -> Self

Build a request-construction error from a static message.

Source

pub fn from_reqwest(error: Error) -> Self

Classify a reqwest error into the closest runtime taxonomy class.

Source

pub fn is_transient(&self) -> bool

Whether the failure is worth retrying: transport failures, timeouts, 429, and 5xx Lets callers wrap any retry policy around the client without spargen shipping one.

Source§

impl Error<Infallible>

Source

pub fn widen<E>(self) -> Error<E>

Widen a never-typed failure into any operation’s error type. Dispatch routines that cannot produce a typed API error return Error<Infallible>; generated shims widen at the call site via .map_err(Error::widen).

Trait Implementations§

Source§

impl<E: Debug> Debug for Error<E>

Source§

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

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

impl<E: Display> Display for Error<E>

Source§

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

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

impl<E: Error + 'static> Error for Error<E>

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

Auto Trait Implementations§

§

impl<E> !Freeze for Error<E>

§

impl<E> !RefUnwindSafe for Error<E>

§

impl<E> !UnwindSafe for Error<E>

§

impl<E> Send for Error<E>
where ResponseValue<E>: Send,

§

impl<E> Sync for Error<E>
where ResponseValue<E>: Sync,

§

impl<E> Unpin for Error<E>
where ResponseValue<E>: Unpin,

§

impl<E> UnsafeUnpin for Error<E>

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