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

Implement source for error types #410

Merged
merged 4 commits into from
May 26, 2022

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented May 17, 2022

Now we have MSRV of 1.41.1 we can implement source for improved error handling.

Patches 1-3 are preparatory cleanup, patch 4 adds all the source impls.

Resolves: #273

apoelstra
apoelstra previously approved these changes May 18, 2022
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 013922c

I did not check that this exhaustively implements Error everywhere that it can/should be.

@tcharding
Copy link
Member Author

I can't guarantee I didn't miss any, I used git grep error::Error to find them. Hopefully with this done it should be obvious to devs that source is part of the error handling boilerplate and to add it if its been missed.

@tcharding
Copy link
Member Author

Face palm, I did this same work in rust-bitcoin and rust-miniscript but I did two things differently in each

  • In one I use fully quallified path std::error::Error and in one I import std::error.
  • In one I put source above Display and in the other I put it below.

My OCD cannot handle that so I'll fix them both tomorrow, sending this to draft. Please comment if you have an opinion on these otherwise I'll arbitrarily pick and do them all the same.

@apoelstra
Copy link
Member

No opinion :).

Put the `SigType` enum below where it is first used instead of in the
middle of the error types/impls.
The `description` method is deprecated since Rust 1.33.0, now we are on
MSRV of 1.41.1 we can remove it in favour of `Display`.
Audit the whole codebase and re-order code around error handling so that
it is all in a uniform layout in the file, specifically

1. Error declaration
2. impl Display ...
3. impl error::Error ...
4. All the From impls

Refactor only, no logic changes. All changes are just moving blocks of
code around.
Now that we have an MSRV of 1.41.1 we can implement `std::Error` by way
of the `cause` method.

Audit the whole codebase and implement `cause` for all error types,
matching explicitly on enum variants so we don't forget to update the
impls if/when the error enums get modified.
@tcharding tcharding marked this pull request as ready for review May 20, 2022 00:27
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 5935d86

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK 5935d86. Checked that all changes correctly pass through the source. Did not check whether there are more Error types that are not covered.

@sanket1729 sanket1729 merged commit c1bba6f into rust-bitcoin:master May 26, 2022
@tcharding tcharding deleted the 05-17-error-source branch May 26, 2022 05:26
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.

Better error reporting by Error::source
3 participants