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

feat: Improved error handling by using thiserror #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OtaK
Copy link

@OtaK OtaK commented Mar 20, 2023

No idea if you would like this to be in; Seems to simplify things a lot when it comes to implementing & extending errors.

My branch is (very) out of date compared to the main branch. I'll get to rebasing it soon.

@jonhoo
Copy link
Owner

jonhoo commented Mar 25, 2023

Thanks! I'm not opposed to the idea, though I'm curious how much this adds to build time — could you measure that (cargo build --timings) and report?

@OtaK OtaK force-pushed the feat/error-handling branch from a6543a9 to 8bbe9c6 Compare March 26, 2023 13:27
@OtaK
Copy link
Author

OtaK commented Mar 26, 2023

Sure - I made sure to run cargo clean between executions. Seems there's a small compilation time gain (probably because the error handling impl is not inline compared to a handwritten impl)

Also rebased this branch on top of main so it should be up to date

Main branch

Cargo Build Timings — fantoccini 0.20.0-rc.4-main.pdf

This branch

Cargo Build Timings — fantoccini 0.20.0-rc.4-feat-error-handling.pdf

@OtaK OtaK marked this pull request as ready for review March 26, 2023 13:34
Comment on lines -27 to +29
url = "2.2.2"
serde = { version = "1.0.103", features = ["derive"] }
serde_json = "1.0.25"
url = "2.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid these changes — the minimal listed patch versions are often there for a reason too.

pub enum NewSessionError {
/// The given WebDriver URL is invalid.
BadWebdriverUrl(ParseError),
#[error("webdriver url is invalid: {0}")]
BadWebdriverUrl(#[from] ParseError),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use #[source] instead of #[from] for any of these we don't already have an explicit impl From for. It's not always the case that a public impl From makes sense, especially not a single one.

pub enum NewSessionError {
/// The given WebDriver URL is invalid.
BadWebdriverUrl(ParseError),
#[error("webdriver url is invalid: {0}")]
Copy link
Owner

@jonhoo jonhoo Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the general guidance from the error working group is that you either print the inner error in the message or you propagate it using Error::source (which both #[from] and #[source] do I believe). This currently does both. Let's remove : {0} here (and for all the others with #[from]/#[source]) and stick with just exposing source.

UnknownMethod => StatusCode::METHOD_NOT_ALLOWED,
UnknownPath => StatusCode::NOT_FOUND,
UnsupportedOperation => StatusCode::INTERNAL_SERVER_ERROR,
Self::ElementClickIntercepted
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to make this change in another PR.

@jonhoo
Copy link
Owner

jonhoo commented Mar 27, 2023

Huh, that's surprising — usually extra proc macros add a decent amount to build time even just because thiserror would have to be built first. It could be because you're building with 32 cores, and so the added size of the dependency graph doesn't matter too much, though I think I'm fine merging a change like this anyway. Thanks for measuring 👍

@jonhoo jonhoo mentioned this pull request Jan 6, 2024
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

Successfully merging this pull request may close these issues.

2 participants