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

Add URL API to Error #1442

Merged
merged 5 commits into from
Jan 27, 2022
Merged

Add URL API to Error #1442

merged 5 commits into from
Jan 27, 2022

Conversation

ecclarke42
Copy link
Contributor

Closes #297 by adding methods to manipulate the URL in Error (url_mut, set_url, clear_url, without_url, making with_url public) and methods to generate formatters (as_url_masked for UrlMaskedError, as_url_hidden for UrlHiddenError, as_url_formatted for UrlFormattedError) which implement Display on a borrowed Error.

Private formatting methods for kind (write_kind) and source (write_source) are added for consistency across formats, as well as write_url_plain and write_url_masked for different URL displays.

Finally, a test was added to make sure the formatters work as expected.


See also, #1299 for prior implementation of some of these


Note: The set_url/clear_url and with_url/without_url pairs are a bit redundant, though the ergonomics are different. I'd be open to removing one of those pairs to make things a little simpler.

@ecclarke42
Copy link
Contributor Author

Also worth considering: should the Debug impls follow Display instead of being derived? This seems useful as errors can often be logged with Debug

Copy link
Owner

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

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

This looks really really cool! I just have some thoughts about reducing the amount of types that are exposed, left comments inline.

src/error.rs Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
@seanmonstar
Copy link
Owner

Well, thinking about this a little more... The most conservative approach would be to just have without_url(). I kinda like that, since I'm increasing less convinced that reqwest should be using Url in the first place (see #1433 for example...).

@ecclarke42
Copy link
Contributor Author

ecclarke42 commented Jan 22, 2022

Honesly, without_url() was my entire original use case 😆. I was just trying to get an example impl of everything in the issue thread to be able to close it out (and a little bit of practice).

Totally fine with restricting it just to that! I'll make the change shortly.

If we're adding without_url, is there any reason to keep making with_url public? Or should that just go back to being pub(crate)?

@ecclarke42
Copy link
Contributor Author

Actually, now that I think about it, keeping url_mut might be good to have as well. I think one of the main drivers from #297 (myself included) was having sensitive data in the query, so being able to do a err.url_mut().map(|u| u.set_query(None)) or similar would keep the rest of the Url available.

On the other hand, that's technically not the URL the request failed on, so the information is less useful than the full URL. With just without_url, the onus is on the caller to do whatever logging they need to determine the host/path/etc.

Elliott Clarke added 3 commits January 21, 2022 20:49
This reverts commit 272cd19.
This reverts commit b0eb6a3.

Edit: Keeps some of the changes we want from the first commit
Copy link
Owner

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@seanmonstar seanmonstar merged commit d3ffb27 into seanmonstar:master Jan 27, 2022
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.

Display Error without url
2 participants