pub struct Error { /* private fields */ }Expand description
An error, with everything a caller or an agent needs to act on it.
Cheap to construct on the failure path and never constructed on the success
path, so the size of this type does not touch the hot path. It is returned
by value rather than boxed because a boxed error means an allocation, and an
allocation on a shard thread aborts (yo-alloc).
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: Code, message: impl Into<String>) -> Error
pub fn new(code: Code, message: impl Into<String>) -> Error
A new error with just a message.
The message is copied into a String here, and that allocation is
wrapped in yo_alloc::allow because a shard thread that allocates
aborts and an error is by definition off the path the budget is for. A
client that sends INCR at a key holding a word should get an error
back, not a server that stops answering everybody else.
The wrap only covers what happens inside this call, so a caller that
builds its message with format! first has already allocated by the
time it gets here. Use Error::fmt for those.
Sourcepub fn fmt(code: Code, args: Arguments<'_>) -> Error
pub fn fmt(code: Code, args: Arguments<'_>) -> Error
A new error whose message needs formatting, built without allocating outside the wrap.
Error::fmt(code, format_args!("no such thing: {name}")) is the shape.
format_args! builds nothing, so the only allocation is the one this
does, and it happens where it is allowed to.
Sourcepub fn at(self, position: u32) -> Error
pub fn at(self, position: u32) -> Error
Attach the argument index or byte offset the error is about.
P10: the first error should teach. A position turns “invalid arguments” into “argument 3 is invalid”, which is the difference between a user reading the docs and a user guessing.
Sourcepub fn with_detail(self, detail: impl Into<String>) -> Error
pub fn with_detail(self, detail: impl Into<String>) -> Error
Attach machine readable detail, such as errno=13 path=/var/lib/app.yo.
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Whether the identical call could succeed later.
Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()