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

Expose a whole lot of errors #485

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

thunderbiscuit
Copy link
Member

@thunderbiscuit thunderbiscuit commented Apr 4, 2024

Description

This PR adds all the boilerplate code related to 4 new error types: AddressError and TransactionError, PsbtParseError, and DescriptorError.

Notes to the reviewers

  • New dependency on bitcoin-internals
  • consensus::encode::Error -> TransactionError. Not sure if there are other places we might use this error, in which case we should name it the same as its Rust counterpart. But as is it just felt weird not to name it TransactionError.

Changelog notice

Added:
  - The Address constructor now returns an AddressError when throwing [#485]
  - The Transaction constructor now returns a TransactionError when throwing [#485]
  - The PartiallySignedTransaction constructor now returns a PsbtParseError when throwing {#485]
  - The Descriptor constructor now returns a DescriptorError when throwing [#485]
 
[#485]: https://github.com/bitcoindevkit/bdk-ffi/pull/485

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Summary by CodeRabbit

  • New Features

    • Added new error handling capabilities across various components for improved robustness.
    • Introduced new error types like AddressError, TransactionError, PsbtParseError, DescriptorError, and FeeRateError.
    • Enhanced FeeRate struct with methods for more precise fee rate calculations.
  • Bug Fixes

    • Updated error handling in Address, Transaction, and Descriptor components to use specific error types for better clarity and troubleshooting.
  • Refactor

    • Renamed errors and updated error handling across multiple files to standardize and simplify codebase.
    • Reordered import statements in esplora.rs for clearer code structure.

Copy link

coderabbitai bot commented Apr 4, 2024

Walkthrough

The update introduces new error handling and dependency enhancements across the bdk-ffi project. It mainly adds several new error types and updates method signatures to handle these errors effectively, ensuring robust and clear error reporting throughout the library. Additionally, a new dependency on bitcoin-internals is introduced to support these changes.

Changes

Files Changes Summary
Cargo.toml Added bitcoin-internals dependency with version 0.2.0 and features alloc.
src/bdk.udl, src/lib.rs Introduced new error enums and interfaces for various components like addresses, transactions, and descriptors. Updated related methods to throw new specific errors.
src/bitcoin.rs, src/descriptor.rs, src/error.rs Updated error handling from Alpha3Error to specific errors like AddressError, TransactionError, and DescriptorError.
src/esplora.rs, src/types.rs Minor adjustments in import ordering and method enhancements in FeeRate struct.

Possibly related issues

  • Issue Implement basic spending policy APIs #80: The implementation of new error enums and interfaces might indirectly support the handling of policies for descriptors, which could be beneficial in implementing basic spending policy APIs. This is because robust error handling is crucial for API reliability, especially when dealing with complex features like spending policies.

Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ab87355 and 97a104f.
Files ignored due to path filters (1)
  • bdk-ffi/Cargo.lock is excluded by !**/*.lock
Files selected for processing (8)
  • bdk-ffi/Cargo.toml (1 hunks)
  • bdk-ffi/src/bdk.udl (5 hunks)
  • bdk-ffi/src/bitcoin.rs (4 hunks)
  • bdk-ffi/src/descriptor.rs (4 hunks)
  • bdk-ffi/src/error.rs (4 hunks)
  • bdk-ffi/src/esplora.rs (1 hunks)
  • bdk-ffi/src/lib.rs (1 hunks)
  • bdk-ffi/src/types.rs (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • bdk-ffi/src/bdk.udl
  • bdk-ffi/src/bitcoin.rs
  • bdk-ffi/src/descriptor.rs
  • bdk-ffi/src/error.rs
  • bdk-ffi/src/esplora.rs
  • bdk-ffi/src/lib.rs
  • bdk-ffi/src/types.rs
Additional comments not posted (1)
bdk-ffi/Cargo.toml (1)

27-27: The addition of bitcoin-internals with version 0.2.0 and the alloc feature is correctly formatted and aligns with the project's needs for enhanced error handling.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -532,13 +532,13 @@ impl TxBuilder {
#[derive(Clone)]
pub(crate) struct BumpFeeTxBuilder {
pub(crate) txid: String,
pub(crate) fee_rate: f32,
pub(crate) fee_rate: Arc<FeeRate>,
Copy link

Choose a reason for hiding this comment

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

Change the fee_rate field in BumpFeeTxBuilder to use Arc<FeeRate> for better type safety and consistency with the rest of the codebase.

-    pub(crate) fee_rate: Arc<FeeRate>,

This modification aligns with the PR's objectives to enhance error handling and improve the codebase's consistency. Using Arc<FeeRate> instead of a primitive type like f32 ensures that the fee rate is handled in a type-safe manner, reducing the risk of errors.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
pub(crate) fee_rate: Arc<FeeRate>,

}
}
}

Copy link

Choose a reason for hiding this comment

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

Add more test cases to cover all the newly added error variants, ensuring comprehensive test coverage.

Would you like me to help by adding some of these test cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

@thunderbiscuit thunderbiscuit changed the title Add Address and Transaction related errors Add a whole lot of errors Apr 5, 2024
@thunderbiscuit thunderbiscuit changed the title Add a whole lot of errors Expose a whole lot of errors Apr 5, 2024
@thunderbiscuit thunderbiscuit force-pushed the errors branch 2 times, most recently from 79284dc to 82ce721 Compare April 5, 2024 18:00
@thunderbiscuit thunderbiscuit requested a review from reez April 10, 2024 17:23
Copy link
Collaborator

@reez reez left a comment

Choose a reason for hiding this comment

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

Love seeing these new errors exposed!

I see bitcoin-internals dependency added (which is a part of rust-bitcoin), I think it was initially added in this commit to convert checksum values into their hexadecimal string representations in lowercase, so it make sense why that dependency was added/selected as the solution.

@reez
Copy link
Collaborator

reez commented Apr 11, 2024

ACK 97a104f

@thunderbiscuit thunderbiscuit merged commit 97a104f into bitcoindevkit:master Apr 11, 2024
25 checks passed
@thunderbiscuit thunderbiscuit deleted the errors branch April 11, 2024 15:41
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.

2 participants