Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message #2293

Closed
DaliborTrampota opened this issue Oct 28, 2023 · 3 comments
Closed

Better error message #2293

DaliborTrampota opened this issue Oct 28, 2023 · 3 comments

Comments

@DaliborTrampota
Copy link

``Hi, Im not sure whether to report this as bug report or request as a feature but I've spend like 3 hours figuring out what the issue is with my middleware and Extension extractor.

error[E0277]: the trait bound `fn(Extension<User>) -> impl futures::Future<Output = impl IntoResponse> {handlers::auth::logged}: Handler<_, _, _>` is not satisfied
   --> src\handlers.rs:38:30
    |
38  |         .route("/user", post(logged).route_layer(&user_middleware))
    |                         ---- ^^^^^^ the trait `Handler<_, _, _>` is not implemented for fn item `fn(Extension<User>) -> impl futures::Future<Output = impl IntoResponse> {handlers::auth::logged}`
    |                         |
    |                         required by a bound introduced by this call
    |
    = help: the following other types implement trait `Handler<T, S, B>`:
              <IntoHandler<H, T, S, B> as Handler<T, S, B>>
              <MethodRouter<S, B> as Handler<(), S, B>>
              <axum::handler::Layered<L, H, T, S, B, B2> as Handler<T, S, B2>>
              <axum_extra::handler::Or<L, R, Lt, Rt, S, B> as Handler<(M, Lt, Rt), S, B>>
note: required by a bound in `post`
   --> C:\Users\dalib\.cargo\registry\src\index.crates.io-6f17d22bba15001f\axum-0.6.20\src\routing\method_routing.rs:407:1
    |
407 | top_level_handler_fn!(post, POST);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `post`
    = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

the issue is my User struct is not deriving Clone trait.. I'd say im intermediate in rust but i still cant read those errors and I tried #[debug_handler] but it didnt do anything

im not even joking when I say that my head hurts. I dont want others to experience this :)
Thank

@davidpdrsn
Copy link
Member

davidpdrsn commented Oct 29, 2023

Believe me if we could improve this we would. You’ll find other issues saying similar things.

The compiler simply doesn’t generate good errors for the kinds of trait implementations axum uses. The problem is not unique to axum and there is a rustc issue about it.

We provide https://docs.rs/axum/0.6.20/axum/attr.debug_handler.html which helps in a lot of cases.

@davidpdrsn davidpdrsn closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2023
@DaliborTrampota
Copy link
Author

DaliborTrampota commented Oct 29, 2023

We provide https://docs.rs/axum/0.6.20/axum/attr.debug_handler.html which helps in a lot of cases.

Yes i mentioned that I tried that but it did not change the error message at all

@davidpdrsn
Copy link
Member

davidpdrsn commented Oct 29, 2023

Ah I see. We probably should add special case for Extension and Clone. We do that for some other know types. I’ll make a separate issue for that!

Update: Done #2294!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants