pub struct TwirpError { /* private fields */ }Expand description
A Twirp error
It is composed of three elements:
- An error
codethat is member of a fixed listTwirpErrorCode - A human error
messagedescribing the error as a string - A set of “
meta” key-value pairs as strings holding arbitrary metadata describing the error.
let error = TwirpError::not_found("Object foo not found").with_meta("id", "foo");
assert_eq!(error.code(), TwirpErrorCode::NotFound);
assert_eq!(error.message(), "Object foo not found");
assert_eq!(error.meta("id"), Some("foo"));Implementations§
Source§impl TwirpError
impl TwirpError
pub fn code(&self) -> TwirpErrorCode
pub fn message(&self) -> &str
pub fn into_message(self) -> String
pub fn new(code: TwirpErrorCode, msg: impl Into<String>) -> Self
pub fn wrap( code: TwirpErrorCode, msg: impl Into<String>, e: impl Error + Send + Sync + 'static, ) -> Self
Sourcepub fn with_meta(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with_meta(self, key: impl Into<String>, value: impl Into<String>) -> Self
Set an associated metadata
pub fn aborted(msg: impl Into<String>) -> Self
pub fn already_exists(msg: impl Into<String>) -> Self
pub fn canceled(msg: impl Into<String>) -> Self
pub fn dataloss(msg: impl Into<String>) -> Self
pub fn invalid_argument( argument: impl Into<String>, msg: impl Into<String>, ) -> Self
pub fn internal(msg: impl Into<String>) -> Self
pub fn deadline_exceeded(msg: impl Into<String>) -> Self
pub fn failed_precondition(msg: impl Into<String>) -> Self
pub fn malformed(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
pub fn out_of_range(msg: impl Into<String>) -> Self
pub fn permission_denied(msg: impl Into<String>) -> Self
pub fn required_argument(argument: &str) -> Self
pub fn resource_exhausted(msg: impl Into<String>) -> Self
pub fn unauthenticated(msg: impl Into<String>) -> Self
pub fn unimplemented(msg: impl Into<String>) -> Self
Trait Implementations§
Source§impl Clone for TwirpError
impl Clone for TwirpError
Source§fn clone(&self) -> TwirpError
fn clone(&self) -> TwirpError
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TwirpError
impl Debug for TwirpError
Source§impl Display for TwirpError
impl Display for TwirpError
Source§impl Error for TwirpError
impl Error for TwirpError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl PartialEq for TwirpError
impl PartialEq for TwirpError
impl Eq for TwirpError
Auto Trait Implementations§
impl Freeze for TwirpError
impl !RefUnwindSafe for TwirpError
impl Send for TwirpError
impl Sync for TwirpError
impl Unpin for TwirpError
impl !UnwindSafe for TwirpError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more