-
Notifications
You must be signed in to change notification settings - Fork 78
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
README: display clear errors in the example #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't modify the readme file directly. The readme is generated from the documentation in the src/lib.rs
file.
done, thanks for the review |
influxdb/src/lib.rs
Outdated
//! if let Err(e) = client.query(weather_readings).await { | ||
//! println!("Error writing result: {e}"); | ||
//! return; | ||
//! } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use .expect()
? I mean we don't actually run this particular doc test, but if we did, it would fail using assert/expect/panic/... but not when using println and return
influxdb/src/lib.rs
Outdated
//! println!("{}", read_result.unwrap()); | ||
//! match client.query(read_query).await { | ||
//! Ok(read_result) => println!("{}", read_result), | ||
//! Err(e) => println!("Error reading result: {e}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use .expect()
?
@msrd0 : The point of this PR is to display a more precise error message to the end user, so we need to display ie. to go from something like "Write result was not okay" to something like "Write result was not okay, because your user is not authorized". I don't think we can do this with |
Alternatively, we could have |
Is the difference between display and debug this big? I just looked it up, and expect("msg") is the same as unwrap_or_else(|e| panic!("msg: {e:?}")). I think given that this code is an example and has no intention to have "perfect" error handling, I'd go with either expect or unwrap and panic. While your code outputs a nice error message to the terminal and exits, I think it is a bit more verbose than necessary for an example, and it needs a bit longer for a human to detect it as error-handling code. But I believe examples should be as concise as possible. |
Using ? is also a good idea |
Now I get |
Ok, I was wrong about the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
Hi,
Building the example in the README raise the following warning:
And running it for me shows:
which is not super helpful.
With the proposed changes, I get:
which is more clear :)
Checklist
cargo fmt --all
cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,reqwest-client -- -D warnings
cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,hyper-client -- -D warnings
cargo doc2readme -p influxdb --expand-macros