#[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 variantsanyhow:anyhow::Errorsupporteyre:eyre::Reportsupport
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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)
quinn only.HTTP/3 connection error (requires quinn feature).
H3Stream(StreamError)
quinn only.HTTP/3 stream error (requires quinn feature).
H3SendDatagram(SendDatagramError)
quinn only.HTTP/3 datagram send error (requires quinn feature).
Anyhow(Error)
anyhow only.Error from the anyhow crate (requires anyhow feature).
Eyre(Report)
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
impl Error
Sourcepub fn other(error: impl Into<BoxedError>) -> Self
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 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()
Source§impl From<Box<dyn Error + Sync + Send>> for Error
impl From<Box<dyn Error + Sync + Send>> for Error
Source§fn from(e: BoxedError) -> Self
fn from(e: BoxedError) -> Self
Source§impl From<ConnectionError> for Error
Available on crate feature quinn only.
impl From<ConnectionError> for Error
quinn only.Source§fn from(e: ConnectionError) -> Self
fn from(e: ConnectionError) -> Self
Source§impl From<Infallible> for Error
impl From<Infallible> for Error
Source§fn from(infallible: Infallible) -> Self
fn from(infallible: Infallible) -> Self
Source§impl From<InvalidUri> for Error
impl From<InvalidUri> for Error
Source§fn from(e: InvalidUri) -> Self
fn from(e: InvalidUri) -> Self
Source§impl From<ParseError> for Error
impl From<ParseError> for Error
Source§fn from(d: ParseError) -> Self
fn from(d: ParseError) -> Self
Source§impl From<SendDatagramError> for Error
Available on crate feature quinn only.
impl From<SendDatagramError> for Error
quinn only.Source§fn from(e: SendDatagramError) -> Self
fn from(e: SendDatagramError) -> Self
Source§impl From<StatusError> for Error
impl From<StatusError> for Error
Source§fn from(e: StatusError) -> Self
fn from(e: StatusError) -> Self
Source§impl From<StreamError> for Error
Available on crate feature quinn only.
impl From<StreamError> for Error
quinn only.Source§fn from(e: StreamError) -> Self
fn from(e: StreamError) -> Self
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> 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<P> Writer for P
impl<P> Writer for P
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,
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,
Response.