Skip to content

taproot: Split errors up#2886

Merged
apoelstra merged 4 commits intorust-bitcoin:masterfrom
tcharding:06-20-taproot-errors
Jun 28, 2024
Merged

taproot: Split errors up#2886
apoelstra merged 4 commits intorust-bitcoin:masterfrom
tcharding:06-20-taproot-errors

Conversation

@tcharding
Copy link
Copy Markdown
Member

Currently there are a couple of errors in the taproot module that are too general, resulting in functions that return a general error type when a specific one would do.

Split two errors out and use them for for enum variants and function returns as possible.

Done as part of #2883

@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Jun 20, 2024
@apoelstra
Copy link
Copy Markdown
Member

In 1be14146dcef2c306b5d6b5d7390fb80047088dd

Both Taproot and Merkle are proper nouns IMO and should stay capitalized.

@apoelstra
Copy link
Copy Markdown
Member

989595b270aa4808905fbf66ca2812bbf842ed51 looks good otherwise! Definitely an improvement.

@tcharding tcharding force-pushed the 06-20-taproot-errors branch from 989595b to dc46eba Compare June 24, 2024 01:25
@tcharding
Copy link
Copy Markdown
Member Author

Hey @jamillambert this is a pretty standard error cleanup PR, if you are interested in the direction we are going with regards to error handling this PR would be a good one to review and understand. If you find error handling boring then don't sweat it, its mainly interesting as a pure engineering problem because there is a whole bunch of nuance in how the Rust language treats enums, enum variant fields, and From impls in relation to public API surface which effects semver. For 1.0 we want to be confident that we can update code without accidentally breaking semver. If all that is over your head don't sweat it, just mentioning it in case you find it interesting.

@tcharding tcharding force-pushed the 06-20-taproot-errors branch from dc46eba to 005f566 Compare June 24, 2024 01:36
@tcharding
Copy link
Copy Markdown
Member Author

Both Taproot and Merkle are proper nouns IMO and should stay capitalized.

I was/am unsure whether it should be "Merkle tree" or "Merkle Tree" - I went with the later. Fixed also "Huffman Tree".

Please note there is one error message changed in the first patch to remove the two sentences.

@storopoli
Copy link
Copy Markdown
Contributor

I was/am unsure whether it should be "Merkle tree" or "Merkle Tree" - I went with the later. Fixed also "Huffman Tree".

In the docstring can be "Merkle tree" (see Wikipedia - Merkle tree for example).
In the enum variants it should be MerkleTree.
So, in my opinion, your approach is correct.

Copy link
Copy Markdown
Contributor

@jamillambert jamillambert left a comment

Choose a reason for hiding this comment

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

I am not sure I understand completely why only 2 of the 5 TaprootError variants were split out. Is it because of the functions that only return one of these, whereas the other variants are returned by functions that can return other variants too and therefore need to be general?

But in terms of achieving what is described I don't see any issues.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should 'tap tree' be 'Taproot tree'?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either that or "taptree" which is one word.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missed capitalization of Taproot

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Legend, thanks. Will fix.

@tcharding
Copy link
Copy Markdown
Member Author

I am not sure I understand completely why only 2 of the 5 TaprootError variants were split out. Is it because of the functions that only return one of these, whereas the other variants are returned by functions that can return other variants too and therefore need to be general?

Yes that is correct. The idea, and if you notice this violated anywhere it should be fixed, is that for every function that returns an enum error type all variants of the error type are returned by the function. This is something that we have been working towards over the last year or so, it is highly likely there are still some that need fixing.

@tcharding tcharding force-pushed the 06-20-taproot-errors branch from 005f566 to a4ea84e Compare June 24, 2024 23:10
@tcharding
Copy link
Copy Markdown
Member Author

I've dropped the first patch that was attempting to fix the capitalization of error messages because there are a whole bunch of anomalies in the taproot module around spelling and capitalization of Taproot tree.

@tcharding
Copy link
Copy Markdown
Member Author

Added #2913 to track the spelling/capitalization stuff that was dropped.

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Other than the doc comment issue ACK 12baa0b891. Feel free to one-ACK after it's fixed without other changes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unrelated but I think error messages should say what's wrong not how it should be right.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, interesting. I think all the error messages in general need work but definitely the ones in taproot.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Left for another day.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be nice to newtype the other variants too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added an additional patch, good reviewing - thanks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doc comment is unrelated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Woops, fixed.

Currently there are a couple of errors in the `taproot` module that are
too general, resulting in functions that return a general error type
when a specific one would do.

Split two errors out and use them for for enum variants and function
returns as possible.
Add two more error types so that the `TaprootError` has all its variants
strongly typed.
The formatter doesn't touch this line but its not uniform with the
surrounding code.
@tcharding tcharding force-pushed the 06-20-taproot-errors branch from a4ea84e to 0c9223a Compare June 26, 2024 05:27
@tcharding
Copy link
Copy Markdown
Member Author

Needs ack from @Kixunil please because changes since last ack are non-trivial. No rush on this one its just error handling stuff.

Kixunil
Kixunil previously approved these changes Jun 26, 2024
Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 0c9223a

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 6a7f780

Copy link
Copy Markdown
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 6a7f780

@apoelstra apoelstra merged commit 6e1fe5e into rust-bitcoin:master Jun 28, 2024
@tcharding tcharding deleted the 06-20-taproot-errors branch June 28, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants