Provide a built-in error wrapper (like AnyError) for anyhow/eyre in axum-extra #3778
patelshudhanshu1999-maker
started this conversation in
Ideas
Replies: 1 comment
-
|
No. axum wont provide such a wrapper. How exactly internal errors should be presented is up the application. There have been several discussions about this previous such as #1941. My opinion about this is unchanged. You're free to make a library for it that others can pull in you want to avoid the boilerplate. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The Problem
Currently, one of the most common friction points for developers coming to Axum (especially from ecosystems like Node.js or simpler Rust frameworks) is that
anyhow::Errororeyre::Reportdo not implementIntoResponse.This forces almost every new Axum project to write the exact same boilerplate wrapper struct just to use the
?operator in their handlers:pub struct AppError(anyhow::Error);
impl IntoResponse for AppError {
fn into_response(self) -> Response {
tracing::error!("Application error: {:#}", self.0);
(
StatusCode::INTERNAL_SERVER_ERROR,
"An internal server error occurred.",
).into_response()
}
}
impl From for AppError where E: Intoanyhow::Error {
fn from(err: E) -> Self {
Self(err.into())
}
}
I am aware this touches on issues mentioned over a year ago in #3211 regarding State access in error handlers, but since that thread went stale, I wanted to revive the specific idea of a simple catch-all.
Could we add an official, standardized wrapper like AnyError to the axum-extra crate (perhaps behind a feature flag)
I know there are community crates that do similar things, but having an official axum_extra utility would provide a trusted, standard path. I'd be more than happy to open a PR for this if the team is open to it
Benefits:
Drastically lowers the barrier to entry for beginners. especially for the nodejs developer
Keeps the axum core completely safe, as this would go in axum-extra.
Standardizes how generic errors are logged and swallowed
Beta Was this translation helpful? Give feedback.
All reactions