Skip to content

Fix types conversion error variants#522

Open
jamillambert wants to merge 2 commits intorust-bitcoin:masterfrom
jamillambert:0226-error-variants
Open

Fix types conversion error variants#522
jamillambert wants to merge 2 commits intorust-bitcoin:masterfrom
jamillambert:0226-error-variants

Conversation

@jamillambert
Copy link
Collaborator

@jamillambert jamillambert commented Feb 26, 2026

Each error variant should be for an individual field. Use an LLM to go through all into.rs files to address the issue, spend longer than doing the job from scratch myself fixing all its errors.

  • Remove a redefinition of an error in v30 that is unchanged from the v29 definition.
  • Add new variants where one variant was used for more than one field. Rename existing variants and update error messages to match the field names.

Closes #521

Comment on lines 68 to 69
/// Conversion of the `hash` field failed.
Hash(hex::HexToArrayError),
/// Conversion of the `wtxid` field failed.
Wtxid(hex::HexToArrayError),
Copy link
Member

Choose a reason for hiding this comment

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

This one is interesting. We re-name the hash field to wtixid in model. I re-checked and believe that is the correct thing to do but I'm not sure about the error variant re-name. Since its done already I guess its ok but it is introducing a precedent [0]. At a minimum we probably should update the docs to be:

    /// Conversion of the `hash` (to `wtxid`) field failed.

And likewise in the Display impl output.

[0] Or do we do this already in other places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it back to hash and updated the docs and Display message. I also did this for tx to unsigned_tx in raw_transaction.

consensus::encode::deserialize_hex::<Transaction>(&self.data).map_err(E::Data)?;
let txid = self.txid.parse::<Txid>().map_err(E::Txid)?;
let wtxid = self.hash.parse::<Wtxid>().map_err(E::Hash)?;
let wtxid = self.hash.parse::<Wtxid>().map_err(E::Wtxid)?;
Copy link
Member

Choose a reason for hiding this comment

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

This is jarring to read (for me personally) now because my eyes expect self.hash to map to E::Hash. Just a comment, I'm open to retraining my eyes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to hash with an updated message.

tcharding
tcharding previously approved these changes Feb 27, 2026
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 43ea5f0

@tcharding
Copy link
Member

I'm ok to merge as is, will wait for you to respond before doing so.

The error types for `hidden` v30 were exact copies of the v29 types.

Remove the `Error` module from v30 and reuse the v29 types instead.
Each error variant should be for an individual field.

Add new variants where one variant was used for more than one field.

Rename existing variants and update error messages to match the field
names.
@jamillambert
Copy link
Collaborator Author

I changed the error variant names to match the version specific type instead of the model type. I also updated the docs and Display messages for the ones that change name. This is not consistent in all RPCs, opened #526 to follow up.

I also noticed an error that was redefined in v30 but there were no changes from v29 so I removed the v30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One error variant per field

2 participants