Skip to main content

Failure

Struct Failure 

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

What a Handler returns for a task that failed: an error result, or, with Failure::abandon, no result at all and the task left to another worker.

use legit_streams::Failure;

let failure = Failure::new("unsupported_model", "no model `x`").field("supported_models", "[\"a\"]");
assert_eq!(failure.error_type(), Some("unsupported_model"));
assert!(!failure.is_abandon());

Implementations§

Source§

impl Failure

Source

pub fn new(error_type: impl Into<String>, message: impl Into<String>) -> Self

An error result with this error_type, such as UNSUPPORTED_MODEL, and message. Error types are an open set in lowercase snake case: a type that isn’t becomes an INTERNAL error, as an unusable reply does.

let failure = legit_streams::Failure::new("decode_failed", "not an image");
assert_eq!(failure.message(), "not an image");
Source

pub fn abandon(reason: impl Into<String>) -> Self

No result, on the bulk lane: the worker leaves the task pending and releases it so another worker claims it at once. For a handler that notices the worker stopping or its lease lost, as Context::checkpoint does, or that can’t run the task now; releasing is this crate’s feature, allowed at any time.

Each release is followed by a claim, and each claim counts a delivery: a task released three times reaches the default delivery limit, and its next claim is answered with max_deliveries_exceeded. A task that shouldn’t run at all is answered with an error, never released.

A FastWorker never releases: it answers an abandoned task with an INTERNAL error, so its caller falls back at once.

assert!(legit_streams::Failure::abandon("shutting down").is_abandon());
Source

pub fn field(self, name: impl Into<String>, value: impl Into<String>) -> Self

Add a field to the error result, such as supported_models.

let failure = legit_streams::Failure::new("unsupported_model", "no").field("supported_models", "[]");
Source

pub fn model_name(self, model_name: impl Into<String>) -> Self

Name the model that ran in the error result’s model_name, rather than echoing the task’s.

Only for a failure of a stage after the model was chosen, when something ran. A task refused before anything ran, such as one answered UNSUPPORTED_MODEL or INVALID_TASK, echoes the name it asked for: don’t set another there.

let failure = legit_streams::Failure::new("decode_failed", "failed").model_name("example-model");
Source

pub const fn is_abandon(&self) -> bool

Whether this abandons the task rather than answering it.

assert!(!legit_streams::Failure::new("decode_failed", "failed").is_abandon());
Source

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

The error type, when the failure is an error with one.

assert_eq!(legit_streams::Failure::abandon("stop").error_type(), None);
Source

pub fn message(&self) -> &str

The error message, or the reason for abandoning.

assert_eq!(legit_streams::Failure::abandon("stop").message(), "stop");

Trait Implementations§

Source§

impl Clone for Failure

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Failure

Source§

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

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

impl Eq for Failure

Source§

impl PartialEq for Failure

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Failure

Auto Trait Implementations§

§

impl Forget for Failure

§

impl Freeze for Failure

§

impl Move for Failure

§

impl RefUnwindSafe for Failure

§

impl Send for Failure
where RawVecInner: Send,

§

impl Sync for Failure
where RawVecInner: Sync,

§

impl Unpin for Failure
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Failure

§

impl UnwindSafe for Failure
where RawVecInner: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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