fix: propagate deserialization errors in proof display instead of hiding them#431
Conversation
📝 WalkthroughWalkthroughThis PR enables Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ing them element_hex_to_ascii and optional_element_hex_to_ascii were silently swallowing Element deserialization errors by falling back to hex encoding. This hides real problems when displaying proofs. Now these functions return Result<String, fmt::Error> so errors propagate through the fmt::Display chain. Supersedes #363. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e9f2b15 to
02bf97a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #431 +/- ##
===========================================
+ Coverage 75.47% 75.51% +0.03%
===========================================
Files 181 181
Lines 46405 46447 +42
===========================================
+ Hits 35025 35073 +48
+ Misses 11380 11374 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix two issues that caused CI failures with --all-features: 1. debugger.rs: add explicit lifetime to RwLockReadGuard to fix mismatched_lifetime_syntaxes clippy lint 2. Cargo.toml: enable grovedb-query/serde feature when grovedb serde feature is active, fixing Serialize/Deserialize derive failure on SizedQuery which contains grovedb_query::Query Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
grovedb/src/operations/proof/util.rs (1)
226-230: Consider logging deserialization errors before discarding context.Since
fmt::Erroris a unit struct that cannot carry error context, the original deserialization error is lost. While this is a limitation ofstd::fmt::Display, consider adding atracing::warn!or similar before returningfmt::Errorto aid debugging when element deserialization fails during proof display.pub fn element_hex_to_ascii(hex_value: &[u8]) -> Result<String, fmt::Error> { - let element = - Element::deserialize(hex_value, GroveVersion::latest()).map_err(|_| fmt::Error)?; + let element = Element::deserialize(hex_value, GroveVersion::latest()).map_err(|e| { + // Consider: tracing::warn!("Element deserialization failed during display: {e}"); + fmt::Error + })?; Ok(element.to_string()) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@grovedb/src/operations/proof/util.rs` around lines 226 - 230, The element_hex_to_ascii function currently swallows the Element::deserialize error by mapping it to fmt::Error; update element_hex_to_ascii to capture the original deserialization error and emit a log (e.g., tracing::warn! or log::warn!) with the error and the offending hex_value before returning fmt::Error so you preserve context for debugging while keeping the function signature unchanged; reference Element::deserialize, GroveVersion::latest, and element_hex_to_ascii to locate the code to modify.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@grovedb/src/operations/proof/util.rs`:
- Around line 226-230: The element_hex_to_ascii function currently swallows the
Element::deserialize error by mapping it to fmt::Error; update
element_hex_to_ascii to capture the original deserialization error and emit a
log (e.g., tracing::warn! or log::warn!) with the error and the offending
hex_value before returning fmt::Error so you preserve context for debugging
while keeping the function signature unchanged; reference Element::deserialize,
GroveVersion::latest, and element_hex_to_ascii to locate the code to modify.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
grovedb/Cargo.tomlgrovedb/src/debugger.rsgrovedb/src/operations/proof/mod.rsgrovedb/src/operations/proof/util.rs
…to_ascii Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cbab5c1 to
9723641
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
grovedb/src/operations/proof/util.rs (1)
226-230: Consider preserving error context for debugging.The original deserialization error is discarded with
.map_err(|_| fmt::Error). Whilefmt::Erroris a unit struct with no payload, losing the underlying error makes debugging harder when formatting fails.Since
fmt::Errorcannot carry context, consider logging the error before converting it, or documenting why the error details are intentionally dropped.💡 Optional: Log error before discarding
pub fn element_hex_to_ascii(hex_value: &[u8]) -> Result<String, fmt::Error> { - let element = - Element::deserialize(hex_value, GroveVersion::latest()).map_err(|_| fmt::Error)?; + let element = Element::deserialize(hex_value, GroveVersion::latest()).map_err(|e| { + // fmt::Error cannot carry context; log for debugging + #[cfg(feature = "logging")] + log::debug!("Element deserialization failed during display: {}", e); + fmt::Error + })?; Ok(element.to_string()) }As per coding guidelines: "Wrap errors with context using
.map_err(|e| Error::CorruptedData(format!("context: {}", e)))pattern" - however,fmt::Erroris a unit struct and cannot carry context, so logging or documentation is the practical alternative here.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@grovedb/src/operations/proof/util.rs` around lines 226 - 230, The current element_hex_to_ascii function discards the deserialization error with .map_err(|_| fmt::Error), losing context; capture the error from Element::deserialize(hex_value, GroveVersion::latest()) as e, log it (e.g., tracing::error! or log::error!) with a concise message including e, then convert to fmt::Error for the function signature so callers still receive fmt::Error but the original error is preserved in logs; alternatively, if you prefer to propagate rich errors, change the return type to return a richer error (propagate e) instead of fmt::Error—refer to element_hex_to_ascii, Element::deserialize, and GroveVersion::latest to locate the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@grovedb/src/operations/proof/util.rs`:
- Around line 226-230: The current element_hex_to_ascii function discards the
deserialization error with .map_err(|_| fmt::Error), losing context; capture the
error from Element::deserialize(hex_value, GroveVersion::latest()) as e, log it
(e.g., tracing::error! or log::error!) with a concise message including e, then
convert to fmt::Error for the function signature so callers still receive
fmt::Error but the original error is preserved in logs; alternatively, if you
prefer to propagate rich errors, change the return type to return a richer error
(propagate e) instead of fmt::Error—refer to element_hex_to_ascii,
Element::deserialize, and GroveVersion::latest to locate the code.
Summary
element_hex_to_asciiandoptional_element_hex_to_asciiwere silently swallowingElementdeserialization errors by falling back to hex encoding viaunwrap_or_elseResult<String, fmt::Error>so errors propagate through thefmt::Displaychainnode_to_string,op_to_string,decode_merk_proof, and theDisplayimpls forProvedPathKeyValue/ProvedPathKeyOptionalValueSupersedes #363 (which was stale and had merge conflicts with the current codebase).
Test plan
cargo check -p grovedbpassesfmt::Errorinstead of being silently replaced with hexGenerated with Claude Code
Summary by CodeRabbit
Chores
Refactor
Bug Fixes