-
Notifications
You must be signed in to change notification settings - Fork 15
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
🧺 use typed errors in public interface #114
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this copies a comment that also is found in `get_with_proof()`, adorning the same `for nibble_depth in nibble_depth..=ROOT_NIBBLE_HEIGHT {}` control flow structure.
replace `anyhow::Result` with the `std` equivalent. we'll want this so we can talk about other errors.
``` pub trait TreeWriter { /// The kind of error that may be returned by [`TreeWriter::write_node_batch()`]. type Error; /// Writes a node batch into storage. fn write_node_batch(&self, node_batch: &NodeBatch) -> Result<()>; } ``` because of these changes, `StateSnapshotReceiver<H>` also has a `FinishError` associated type. this is threaded through from the tree writer.
as with the writer commit, this introduces an associated type so that implementors of the reader trait may opt to use a different error type. ``` pub trait TreeReader { /// The type of error that may be returned by [`TreeReader`] storage lookups. type Error; /// Gets node given a node key. Returns `None` if the node does not exist. fn get_node_option(&self, node_key: &NodeKey) -> Result<Option<Node>, Self::Error>; /// Gets a value by identifier, returning the newest value whose version is *less than or /// equal to* the specified version. Returns None if the value does not exist. fn get_value_option( &self, max_version: Version, key_hash: KeyHash, ) -> Result<Option<OwnedValue>, Self::Error>; /// Gets the rightmost leaf. Note that this assumes we are in the process of restoring the tree /// and all nodes are at the same version. fn get_rightmost_leaf(&self) -> Result<Option<(NodeKey, LeafNode)>, Self::Error>; } ``` some interfaces flatten the inner `Option<T>`, from `Result<Option<T>, E>` values into simpler `Result<T, E>` values, so those are pulled into a standalone extension trait. this lets the `TreeReader` trait itself be agnostic about its errors.
now that we've updated the `TreeReader` trait to include an associated error type, the constructor for `TreeCache<'a, R>` does not need to return an `anyhow::Error`.
previously in our `TreeWriter` work, we passed by this `StateSnapshotReceiver` trait. this swings back around to add a concrete error type to `JellyfishMerkleRestore`'s implementation of that trait. a `RestoreError<E>`, parameterized across the write error `E` of backing storage, may be returned by the `add_chunk_impl` method.
before we handle the constructor for `JellyfishMerkleRestore`, let's make an error type for partial node recovery. NB: despite the horizontal motion in `new()`, no code in the body is changed, save `map_err(|_| ..)` conversions to wrap i/o errors in `RecoveryError::Read(_)`.
this follows up on a `todo` comment from our work on `add_chunk()`.
this encapsulates the errors that can occur when we look up a value in the merkle tree.
…pError` this introduces some additional variants to `LookupError<E>`, and transforms `get_with_exclusion_proof()` s.t. it now returns a typed `LookupError<E>` as well. some documentation is also added to the function, while we are here.
cratelyn
force-pushed
the
kate/jmt-with-typed-errors
branch
from
May 4, 2024 20:25
aa51392
to
078eafa
Compare
Why is this closed? Are there plans to support this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this updates
jmt
so that its public interface uses concrete, typed error variants rather than boxeddyn
errors.🚧 todo's
some todo's before i mark this as officially ready for review
no_std
compatibility (considersnafu
)#[non_exhaustive]
to errorsCargo.toml
package versionwhile i sort these things out, i may be force-pushing to this branch regularly. you've been warned!
👁️ note for reviewers
a pattern that shows up in some places is replacing...
...with...
...we should keep a close eye out for conditionals that are not inverted when this transformation is applied.