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
impl Failure
Sourcepub fn new(error_type: impl Into<String>, message: impl Into<String>) -> Self
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");Sourcepub fn abandon(reason: impl Into<String>) -> Self
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());Sourcepub fn field(self, name: impl Into<String>, value: impl Into<String>) -> Self
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", "[]");Sourcepub fn model_name(self, model_name: impl Into<String>) -> Self
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");Sourcepub const fn is_abandon(&self) -> bool
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());Sourcepub fn error_type(&self) -> Option<&str>
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);