-
Notifications
You must be signed in to change notification settings - Fork 124
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
Replace failure with anyhow and thiserror #123
Conversation
fe1fbad
to
5c62ab7
Compare
Thanks a lot for the PR! I've been thinking if failure is necessary since I first saw it in the codebase. Do you think anyhow is worth it still? I read that these kind of libraries are often used for binaries, not libraries. This is a good opportunity to just get rid of failure/anyhow. I'll investigate a bit about that when I have time. |
Hey, yeah I have the same thoughts. Ideally we'd only use |
I think we could remove I don't personally use |
I kind of agree with @marioortizmanero, Oh the other hand,
As for |
Sounds good to me. If you're both behind it I'll see what I can do! |
8cb1ced
to
19d2aeb
Compare
I've added some changes. Please have a look at the new error type and let me know what you think. Tried to follow |
19d2aeb
to
f263ddd
Compare
I also have a branch with a few 'misc' changes like some clippy lints and code fixes that I came across while working on this, should I open another PR for those? |
Yep, it would be better to open a new PR for these 'misc' changes, because there is nothing related to this PR: |
StatusCode::TOO_MANY_REQUESTS => Self::RateLimitedError( | ||
response | ||
.headers() | ||
.get(reqwest::header::RETRY_AFTER) |
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.
This was rewritten because indexing directly can panic (though it is unlikely). Doing a match on
if let Some(duration) = response.headers().get(...).and_then(|header| header.to_str().ok()) {
was suddenly a lot going on on a single line so I used another and_then
instead.
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.
I agree, It's better this way IMO
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.
Yeah, it's more robust than before :)
status @ StatusCode::FORBIDDEN | status @ StatusCode::NOT_FOUND => response | ||
.json::<ApiError>() | ||
.map(Into::into) | ||
.unwrap_or_else(|_| status.into()), |
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.
This was rewritten simply to match the same functional style as above for consistency.
Looks good to me! The only nitpick: IMO the "Error" suffix in the error types are unnecessary. Can you also add this in the |
After looking at it, you're right. The rust api guidelines recommend calling it |
f263ddd
to
fa3d0b1
Compare
Thanks for your help! This can probably be merged now (not sure if I should be merging PRs myself). @ramsayleung, should we think about releasing a new version, or do we wait for #120? That one is going to take longer than I expected and there are quite a few breaking changes already. Or maybe it's better to release all the breaking changes at once? Not sure. We could create a new issue tracking the new release like many other libraries do, or at least use GitHub milestones. |
I suggest to wait for #120, so we don't need to release a version of breake changes twice.
Yep, It's a good idea. I personnally suggest to create a milestone of stable version, and label this version as the one last version of breake change before the stable version. After cleaning up the blocking module, and refacting codebase of error handle, I think we are marching to the stable version, |
Merged :) |
I personally think we're nowhere near a stable version yet. After #120, there's still #116 and #109 with breaking changes. #4 might also include some breaking changes, and the newly opened #124 could change some things as well. |
Ooops, it still have some features needing to be implemented :) |
As described in #122 ,
failure
is deprecated. This replaces it with anyhow and thiserror.Closes #122