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

migrate object.rs to snafu error handling #3858

Merged
merged 11 commits into from
Aug 7, 2024

Conversation

cryptoni9n
Copy link
Collaborator

@cryptoni9n cryptoni9n commented Jul 16, 2024

part of fix for #3192
makes SnafuError public within error.rs;
adds parse errors to error.rs;
updates test in parse.rs;
migrates object.rs to snafu error handling from anyhow

@cryptoni9n cryptoni9n changed the title migrate-object.rs-to-snafu-error-handling migrate object.rs to snafu error handling Jul 16, 2024
Copy link
Collaborator

@casey casey left a comment

Choose a reason for hiding this comment

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

Nice! A few comments!

  • Error enum variants shouldn't have Error in their name, since it's redundant, i.e., they're variants in an enum which already has Error in the name.
  • snafu errors which add context to an existing error should include the source error
  • To construct a snafu error, use snafu_context, and then provide an error selector, which in the case of the error::Error enum, will be error::EnumVariantName.

I just pushed a commit which does these for AddressParseError:

  • It's now just called AddressParse
  • It includes the underlying error, which is a bitcoin::address::Error
  • It uses .snafu_context(error::AddressParse { … }) to construct the error

Copy link
Collaborator Author

@cryptoni9n cryptoni9n left a comment

Choose a reason for hiding this comment

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

thanks, for making these changes. they'll be very useful for me as a reference for the requested updates.

@cryptoni9n cryptoni9n requested a review from casey August 7, 2024 14:29
@cryptoni9n
Copy link
Collaborator Author

cryptoni9n commented Aug 7, 2024

Hi Casey - Please see the latest changes. I did my best in figuring out what the underlying / source error should be for each of these parse errors, but had to make a few things public from crates/ordinals/src/lib.rs in order to reference them - not sure if that's ok or not. Please take a look and let me know what you think.

apologies for the clusterfuck of commits, still trying to get the hang of this.

Copy link
Collaborator

@casey casey left a comment

Choose a reason for hiding this comment

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

Looks good to me! I changed the name of the argument in from_str to input, which allows using the field shorthand syntax ({ input } instead of { input: s }) since it looks a little nicer.

@casey casey enabled auto-merge (squash) August 7, 2024 22:32
@casey casey merged commit c24d136 into ordinals:master Aug 7, 2024
5 checks passed
@cryptoni9n cryptoni9n deleted the outgoing.rs-to-snafu branch August 7, 2024 23:25
danadi7 pushed a commit to sadoprotocol/ord that referenced this pull request Sep 20, 2024
* Change test-bitcoincore-rpc to mockcore in README.md (ordinals#3842)

* Commit twice to work around redb off-by-one bug (ordinals#3856)

* Release 0.19.1 (ordinals#3864)

- Bump version: 0.19.0 → 0.19.1
- Update changelog
- Update changelog contributor credits
- Update dependencies

* Update Portuguese Translation pt.po (ordinals#3837)

* Updated Chinese translation  (ordinals#3881)

* Fix rune links for runes with no symbol (ordinals#3849)

* Suppress printing sat_ranges by default (ordinals#3867)

* Re-enter beta (ordinals#3884)

* Update pointer specification (ordinals#3861)

* Clarify that unused runes tags should not be used (ordinals#3885)

* Migrate object.rs to snafu error handling (ordinals#3858)

* Make index settings harder to misuse (ordinals#3893)

* Don't unnecessarily insert into utxo cache when indexing addresses (ordinals#3894)

* Remove trailing space from runes specification (ordinals#3896)

* Serve responses with cross origin isolation headers (ordinals#3898)

* List all Bitcoin Core wallets (ordinals#3902)

* Make first first and last sat in range clickable (ordinals#3903)

* Migrate Outgoing to SnafuError (ordinals#3854)

* Update Bitcoin Core deploy to 27.1 (ordinals#3912)

* Add sat_balance to address API (ordinals#3905)

Co-authored-by: raph <[email protected]>

* Add Dutch translation to Ordinals Handbook (ordinals#3907)

* Migrate chain.rs to snafu error (ordinals#3904)

* Bump version to 0.20.0-dev (ordinals#3916)

* Revert "Serve responses with cross origin isolation headers" (ordinals#3920)

* Remove inscription content type counts from /status page (ordinals#3922)

* Unified OUTPOINT_TO_UTXO_ENTRY table (ordinals#3915)

- Upgrade `redb` to 2.1.1
- Remove `--index-spent-sats`
- Remove redundant pointer handling in `index_inscriptions()`
- Fix incorrect `is_output_spent()` results when not using `--index-sats`
- Unify UTXO index data in `OUTPOINT_TO_UTXO_ENTRY` table
- Read addresses from index when exporting

* Add address field to `/r/inscription/:id` (ordinals#3891)

* Add inscriptions and runes details to address API endpoint (ordinals#3924)

* Release 0.20.0 (ordinals#3928)

- Bump ord version: 0.19.1 → 0.20.0
- Bump ordinals version: 0.0.9 → 0.0.10
- Update changelog
- Update changelog contributor credits
- Update dependencies

---------

Co-authored-by: Anchor <[email protected]>
Co-authored-by: Casey Rodarmor <[email protected]>
Co-authored-by: 0xArtur <[email protected]>
Co-authored-by: Dr.JingLee <[email protected]>
Co-authored-by: nine <[email protected]>
Co-authored-by: Bohdan Cryptolions <[email protected]>
Co-authored-by: raph <[email protected]>
Co-authored-by: Patrick Collins <[email protected]>
Co-authored-by: Tibebtc <[email protected]>
Co-authored-by: partialord <[email protected]>
Co-authored-by: Eloc <[email protected]>
Co-authored-by: twosatsmaxi <[email protected]>
dcorral added a commit to sadoprotocol/ord that referenced this pull request Oct 24, 2024
* Change test-bitcoincore-rpc to mockcore in README.md (ordinals#3842)

* Commit twice to work around redb off-by-one bug (ordinals#3856)

* Release 0.19.1 (ordinals#3864)

- Bump version: 0.19.0 → 0.19.1
- Update changelog
- Update changelog contributor credits
- Update dependencies

* Update Portuguese Translation pt.po (ordinals#3837)

* Updated Chinese translation  (ordinals#3881)

* Fix rune links for runes with no symbol (ordinals#3849)

* Suppress printing sat_ranges by default (ordinals#3867)

* Re-enter beta (ordinals#3884)

* Update pointer specification (ordinals#3861)

* Clarify that unused runes tags should not be used (ordinals#3885)

* Migrate object.rs to snafu error handling (ordinals#3858)

* Make index settings harder to misuse (ordinals#3893)

* Don't unnecessarily insert into utxo cache when indexing addresses (ordinals#3894)

* Remove trailing space from runes specification (ordinals#3896)

* Serve responses with cross origin isolation headers (ordinals#3898)

* List all Bitcoin Core wallets (ordinals#3902)

* Make first first and last sat in range clickable (ordinals#3903)

* Migrate Outgoing to SnafuError (ordinals#3854)

* Update Bitcoin Core deploy to 27.1 (ordinals#3912)

* Add sat_balance to address API (ordinals#3905)

Co-authored-by: raph <[email protected]>

* Add Dutch translation to Ordinals Handbook (ordinals#3907)

* Migrate chain.rs to snafu error (ordinals#3904)

* Bump version to 0.20.0-dev (ordinals#3916)

* Revert "Serve responses with cross origin isolation headers" (ordinals#3920)

* Remove inscription content type counts from /status page (ordinals#3922)

* Unified OUTPOINT_TO_UTXO_ENTRY table (ordinals#3915)

- Upgrade `redb` to 2.1.1
- Remove `--index-spent-sats`
- Remove redundant pointer handling in `index_inscriptions()`
- Fix incorrect `is_output_spent()` results when not using `--index-sats`
- Unify UTXO index data in `OUTPOINT_TO_UTXO_ENTRY` table
- Read addresses from index when exporting

* Add address field to `/r/inscription/:id` (ordinals#3891)

* Add inscriptions and runes details to address API endpoint (ordinals#3924)

* Release 0.20.0 (ordinals#3928)

- Bump ord version: 0.19.1 → 0.20.0
- Bump ordinals version: 0.0.9 → 0.0.10
- Update changelog
- Update changelog contributor credits
- Update dependencies

* Bump version to 0.20.0-dev (ordinals#3929)

* Add test to remind us to fix the UtxoEntry redb type name (ordinals#3934)

* Put AddressInfo into api module (ordinals#3933)

* Fix clippy lint (ordinals#3937)

* Add inscription index to /status (ordinals#3938)

* Remove unnecessary symbols in docs/src/guides/testing.md (ordinals#3945)

* Add inscription examples to handbook (ordinals#3769)

* Allow scrolling in iframe (ordinals#3947)

* Skip serializing None in batch::File (ordinals#3943)

* Fix /output page (ordinals#3948)

* Add `/satpoint/<SATPOINT>` endpoint (ordinals#3949)

* Don't log RPC connections to bitcoind (ordinals#3952)

* Start indexing at correct block height (ordinals#3956)

* Fix output API struct (ordinals#3957)

* Remove dependency on `ord-bitcoincore-rpc` crate (ordinals#3959)

* Keep sat ranges in low-level format (ordinals#3963)

* Implement burn for wallet command (ordinals#3437)

* Add multi parent support to wallet (ordinals#3228)

* Get parents using `as_slice` instead of converting to `Vec` (ordinals#3972)

* Rename parents_values -> parent_values (ordinals#3973)

* Fix non-existant output lookup (ordinals#3968)

* Release 0.20.1 (ordinals#3975)

* Refactor burn command (ordinals#3976)

* Remove regtest.ordinals.net just recipes (ordinals#3978)

* Add `ord verify` (ordinals#3906)

* Release 0.21.0 (ordinals#3997)

- Bump version: 0.20.1 → 0.21.0
- Update changelog
- Update changelog contributor credits
- Update dependencies

* Remove /runes/balances API endpoint (ordinals#3980)

* Update rust-bitcoin in ord (ordinals#3962)

* Revert redb to 2.1.3 (ordinals#4003)

* Release 0.21.1 (ordinals#4006)

* Update Bitcoin Core install script (ordinals#4007)

* Remove pre-alpha warning from ord help (ordinals#4011)

* Change mint progress to `mints / terms.cap` (ordinals#4012)

* Only show rune mint progress during mint (ordinals#4013)

* Show if JSON API is enabled on /status (ordinals#4014)

* Fix build error

---------

Co-authored-by: Anchor <[email protected]>
Co-authored-by: Casey Rodarmor <[email protected]>
Co-authored-by: 0xArtur <[email protected]>
Co-authored-by: Dr.JingLee <[email protected]>
Co-authored-by: nine <[email protected]>
Co-authored-by: Bohdan Cryptolions <[email protected]>
Co-authored-by: raph <[email protected]>
Co-authored-by: Patrick Collins <[email protected]>
Co-authored-by: Tibebtc <[email protected]>
Co-authored-by: partialord <[email protected]>
Co-authored-by: Eloc <[email protected]>
Co-authored-by: twosatsmaxi <[email protected]>
Co-authored-by: tiaoxizhan <[email protected]>
Co-authored-by: onchainguy <[email protected]>
Co-authored-by: lifofifo <[email protected]>
Co-authored-by: dcorral <[email protected]>
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.

3 participants