Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error { Hyper(Error), HttpParse(ParseError), HttpStatus(StatusError), Io(Error), SerdeJson(Error), InvalidUri(InvalidUri), H3Connection(ConnectionError), H3Stream(StreamError), H3SendDatagram(SendDatagramError), Anyhow(Error), Eyre(Report), Other(BoxedError), }
Expand description

The main error type used throughout Salvo.

This enum encompasses all error types that can occur during request processing, from low-level I/O errors to HTTP-specific errors.

§Rendering

Error implements Scribe, which means it can be rendered directly to a response. Most error variants render as a 500 Internal Server Error, except for HttpStatus which uses the status code from the contained StatusError.

§Error Conversion

Common error types automatically convert to Error:

use salvo_core::Error;

// I/O errors
let io_err: Error = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found").into();

// JSON errors
let json_err: Error = serde_json::from_str::<()>("invalid").unwrap_err().into();

// Custom errors
let custom: Error = Error::other(MyError);

§Feature-Gated Variants

Some variants are only available with specific features:

  • quinn: HTTP/3 error variants
  • anyhow: anyhow::Error support
  • eyre: eyre::Report support

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Hyper(Error)

Error from the hyper HTTP library.

These errors typically occur during low-level HTTP processing.

§

HttpParse(ParseError)

HTTP parsing error.

Occurs when request data cannot be parsed correctly.

§

HttpStatus(StatusError)

HTTP status error with an associated status code.

Unlike other variants, this error uses its contained status code when rendering to a response.

§

Io(Error)

Standard I/O error.

Common for file operations and network issues.

§

SerdeJson(Error)

JSON serialization/deserialization error.

§

InvalidUri(InvalidUri)

Invalid URI error.

Occurs when a URI cannot be parsed.

§

H3Connection(ConnectionError)

Available on crate feature quinn only.

HTTP/3 connection error (requires quinn feature).

§

H3Stream(StreamError)

Available on crate feature quinn only.

HTTP/3 stream error (requires quinn feature).

§

H3SendDatagram(SendDatagramError)

Available on crate feature quinn only.

HTTP/3 datagram send error (requires quinn feature).

§

Anyhow(Error)

Available on crate feature anyhow only.

Error from the anyhow crate (requires anyhow feature).

§

Eyre(Report)

Available on crate feature eyre only.

Error from the eyre crate (requires eyre feature).

§

Other(BoxedError)

Any other error type wrapped as a boxed trait object.

Use Error::other to create this variant from any error type.

Implementations§

Source§

impl Error

Source

pub fn other(error: impl Into<BoxedError>) -> Self

Creates an Error from any error type.

This is useful for wrapping custom error types that don’t have a dedicated variant in the Error enum.

§Example
use salvo_core::Error;

#[derive(Debug)]
struct MyError(String);

impl std::fmt::Display for MyError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::error::Error for MyError {}

let error = Error::other(MyError("something went wrong".into()));

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

1.30.0 · Source§

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

👎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<Box<dyn Error + Sync + Send>> for Error

Source§

fn from(e: BoxedError) -> Self

Converts to this type from the input type.
Source§

impl From<ConnectionError> for Error

Available on crate feature quinn only.
Source§

fn from(e: ConnectionError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: IoError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Available on crate feature anyhow only.
Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Infallible> for Error

Source§

fn from(infallible: Infallible) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidUri> for Error

Source§

fn from(e: InvalidUri) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(d: ParseError) -> Self

Converts to this type from the input type.
Source§

impl From<Report> for Error

Available on crate feature eyre only.
Source§

fn from(e: Report) -> Self

Converts to this type from the input type.
Source§

impl From<SendDatagramError> for Error

Available on crate feature quinn only.
Source§

fn from(e: SendDatagramError) -> Self

Converts to this type from the input type.
Source§

impl From<StatusError> for Error

Source§

fn from(e: StatusError) -> Self

Converts to this type from the input type.
Source§

impl From<StreamError> for Error

Available on crate feature quinn only.
Source§

fn from(e: StreamError) -> Self

Converts to this type from the input type.
Source§

impl Scribe for Error

Source§

fn render(self, res: &mut Response)

Render data to Response.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl !UnwindSafe for Error

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<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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
Source§

impl<P> Writer for P
where P: Scribe + Send,

Source§

fn write<'life0, 'life1, 'life2, 'async_trait>( self, _req: &'life0 mut Request, _depot: &'life1 mut Depot, res: &'life2 mut Response, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, P: 'async_trait,

Write data to Response.