-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
FromData Failures cannot be caught by error catchers and are not debug-logged #1199
Comments
This is covered in the docs at https://api.rocket.rs/v0.4/rocket/data/trait.FromData.html#outcomes
We do want to expand the functionality so that errors from just about anywhere could go to error catchers (#749 (comment)), but it needs some work in rustc. |
Do you have an example how I would do this? Or isn't rustc providing needed functionally currently. Anyways I could easily workaround this with bit of Custom responder. Rocket is really nice! Thank you! |
|
This example is great and I can now use types in a really simple way. Thank you! |
Hi all, Using I'm having a similar issue here with Request Guards. I have a couple custom guards that can fail in various ways (the database connection fails, missing headers/cookies, etc) and even though I encapsulate these failures in an Error type and pass them back to Rocket, they never get logged as reasons for I could always get around this in my own code by writing my own logging in the Request Guard (which can sometimes hurt readability) or by wrapping the from_request method like so: ...
impl FromRequest for MyRequestGuard {
fn from_request(r: Request) -> Outcome<Self, Self::Error> {
match _from_request(r) {
o@Outcome::Success(_) => o,
Outcome::Failure((s,e)) => {
info!("MyRequestGuard failed with: {} - {}", s, e);
Outcome::Failure((s, e))
}
o@Outcome::Forward(_) => o
}
}
}
fn _from_request(r: Request) -> Outcome<MyRequestGuard, MyError> {
// ...
} But this seems like unnecessary boilerplate for something Rocket is able to handle. This issue is exasperated for Data Guards, too. In order to do logging it seems like I have to use |
Errors and forwards from all guards are now being logged by Rocket. |
I think logging is only part of the solution. I'd also like to be able to act on it in catchers which is probably the primary thing in this issue. |
There is already an issue for handling typed errors in catchers. See #749. |
Alright. |
Hello,
Bug reports must include:
0.4.2, rustc --version
rustc 1.42.0-nightly (0de96d37f 2019-12-19)
OSX 10.5.2
3. A brief description of the bug that includes:
* The nature of the bug.
FromData and FromDataSimple ask (status, Error) for Failure. As far as I can see the Error is not populated any where.
It would be good to get Error output to up to default catcher response Outputs.
Simplest FromDataSimple Guard do not show Error any where, not even debug level logs.
Rocket transforms rocket::request::Outcome to rocket::Outcome and just drops the addition E info all together.
It would be very convenient if the Error info could be populated from data parsers to above levels. Now I need to do FromDataSimple functionality in post route fn itself.
The text was updated successfully, but these errors were encountered: