Overview
TreeError represents errors that occur during tree operations such as insertions, updates, and proof generation. These are logical errors related to tree constraints and operations.
Error Variants
MaxDepthExceeded
MaxDepthExceeded
Returned when: An operation would cause the tree to exceed its compile-time maximum depth.The
max_depth field indicates the configured maximum depth that would be violated.Common causes:- Inserting too many leaves for the configured
MAX_DEPTH - Tree capacity exhausted for the given depth limit
- Increase
MAX_DEPTHat compile time if possible - Split data across multiple trees
IndexOutOfRange
IndexOutOfRange
Returned when: Attempting to access a leaf index outside the valid range The error includes both the requested
[0, size).index and the current tree size.Common causes:- Accessing a leaf that hasn’t been inserted yet
- Using an incorrect index calculation
- Stale size information
- Validate indices before access
- Check current tree size with
tree.size()
EmptyBatch
EmptyBatch
Returned when: Common causes:
insert_many is called with an empty slice.- Passing an empty vector or slice to batch insertion
- Logic error in batch preparation
- Validate batch is non-empty before calling
insert_many - Handle empty batches separately in application logic
CapacityExceeded
CapacityExceeded
Returned when: The tree’s This indicates an internal overflow when converting between size types.Common causes:
u64 size cannot be represented as usize.- Operating on 32-bit systems with very large trees
- Size calculations exceeding
usize::MAX
- Use a 64-bit platform for very large trees
- Split data across multiple trees
MathError
MathError
Returned when: An internal mathematical operation fails.This is a generic error for arithmetic issues during tree operations.Common causes:
- Integer overflow in internal calculations
- Invalid arithmetic operations
- Report as a bug if encountered
- Check for edge cases in input data
InvalidProofDepth
InvalidProofDepth
Returned when: A consistency proof has an unexpected depth.The error includes both the
expected depth and the actual depth received.Common causes:- Proof generated for different tree configuration
- Corrupted or modified proof data
- Version mismatch between proof generation and verification
- Regenerate the proof with correct parameters
- Verify tree configurations match
NoUpdateNeeded
NoUpdateNeeded
Returned when: A proof update operation is requested but the old and new sizes are identical.This indicates the update is a no-op since the tree size hasn’t changed.Common causes:
- Calling update with
old_size == new_size - Logic error in update flow
- Check if sizes differ before requesting update
- Skip update operation for same-size transitions
Error Handling
Basic Pattern
Validation Before Operations
Converting to Application Errors
Traits
TreeError implements:
Debug- for debugging outputDisplay- for user-friendly error messagesPartialEq,Eq- for error comparisonstd::error::Error- for error trait compatibility
See Also
- StorageError - Storage and I/O errors
- LeanIMT - Main tree interface
- Proof Generation - Working with Merkle proofs
