Skip to main content

Error

Enum Error 

Source
pub enum Error {
    Auth(AuthError),
    Store(StoreError),
    Password(PasswordError),
    Task(JoinError),
}
Available on crate feature server only.
Expand description

The error of an Auth operation: either an AuthError to answer the request with, or an internal failure.

Classify one with auth_error. Once it has passed through ? into an app’s own error, such as an anyhow::Error, use find_auth_error on that error rather than downcasting it to AuthError, which misses a refusal wrapped as Error::Auth and so answers a Forbidden as an internal failure.

An internal failure’s message carries its cause, such as storage failed: database is locked, so logging it with {error} says what went wrong. Its source continues below that cause, so a chain printer such as anyhow’s {:#} does not repeat it. The message is for logs: answer the client with something generic, as the axum08 integration and the musliweb05 Connection do.

Variants§

§

Auth(AuthError)

The request is refused, as the AuthError says.

§

Store(StoreError)

The store failed.

§

Password(PasswordError)

Hashing a password failed.

§

Task(JoinError)

A blocking task, such as hashing, panicked or was cancelled.

Implementations§

Source§

impl Error

Source

pub fn auth_error(&self) -> Option<&AuthError>

The AuthError to answer with, or None for an internal failure.

This is how to tell a refusal, which the client should see, from an internal failure, which it should not.

Source

pub fn find_auth_error<'a>( error: &'a (dyn StdError + 'static), ) -> Option<&'a AuthError>

The AuthError somewhere in error’s chain of sources, whether bare or as an Error::Auth, or None when the chain holds no refusal.

For an app’s own error that a watchword Error reached through ?. With anyhow, pass &*error; an app error type that wraps Error has to name it as its source.

use watchword::AuthError;
use watchword::core::Error;

#[derive(Debug)]
struct AppError(Error);

impl std::fmt::Display for AppError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("the request failed")
    }
}

impl std::error::Error for AppError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        Some(&self.0)
    }
}

let error = AppError(Error::from(AuthError::Forbidden));
assert_eq!(Error::find_auth_error(&error), Some(&AuthError::Forbidden));

let error = AppError(Error::from(watchword::store::StoreError::new("disk full")));
assert_eq!(Error::find_auth_error(&error), None);

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn StdError + '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
Source§

impl From<AuthError> for Error

Source§

fn from(error: AuthError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for RequestError

Available on crate feature musliweb05 only.
Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<JoinError> for Error

Source§

fn from(error: JoinError) -> Self

Converts to this type from the input type.
Source§

impl From<PasswordError> for Error

Source§

fn from(error: PasswordError) -> Self

Converts to this type from the input type.
Source§

impl From<StoreError> for Error

Source§

fn from(error: StoreError) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for Error

Available on crate feature axum08 only.

Answers an AuthError as that error does (watchword-core implements IntoResponse for it). Any other failure is logged and answered with a bare 500, so internals never reach the client.

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasAllProps<(), T> for T

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<E> ResponseError for E
where E: 'static + Send + Display,

Source§

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

Write the human readable message of the error. Read more
Source§

fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>

Encode the typed payload of the error, if it has one, by calling ErrorPayload::encode. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
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