fix: avoid validating forest car twice in AnyCar::new#6793
fix: avoid validating forest car twice in AnyCar::new#6793LesnyRumcajs merged 3 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughRefactors CAR validation/construction: Changes
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 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 docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/db/car/many.rs (1)
133-140: Use.with_context()to preserve the error chain.The current pattern with
map_err(|e| anyhow::anyhow!("...: {e}", ...))loses the original error chain because{e}only captures theDisplayoutput, not the underlying causes. Using.with_context()preserves the full error chain for better debugging.♻️ Suggested refactor
pub fn read_only_file(&self, file: impl AsRef<Path>) -> anyhow::Result<()> { - (|| { - self.read_only(AnyCar::new(EitherMmapOrRandomAccessFile::open( - file.as_ref(), - )?)?) - })() - .map_err(|e| anyhow::anyhow!("failed to load CAR at {}: {e}", file.as_ref().display())) + self.read_only(AnyCar::new(EitherMmapOrRandomAccessFile::open( + file.as_ref(), + )?)?) + .with_context(|| format!("failed to load CAR at {}", file.as_ref().display())) }As per coding guidelines: "Use
anyhow::Result<T>for most operations and add context with.context()when errors occur".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/db/car/many.rs` around lines 133 - 140, The current read_only_file implementation replaces the original error chain by mapping errors into a new anyhow error string; update read_only_file so that failures from EitherMmapOrRandomAccessFile::open, AnyCar::new, or self.read_only are propagated with context instead of being recreated: call .context(...) (or .with_context(...)) on the fallible operations inside read_only_file (around the EitherMmapOrRandomAccessFile::open and/or the outer closure) to attach the "failed to load CAR at <path>" message while preserving the original error chain for read_only, AnyCar::new and EitherMmapOrRandomAccessFile::open.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/db/car/many.rs`:
- Around line 133-140: The current read_only_file implementation replaces the
original error chain by mapping errors into a new anyhow error string; update
read_only_file so that failures from EitherMmapOrRandomAccessFile::open,
AnyCar::new, or self.read_only are propagated with context instead of being
recreated: call .context(...) (or .with_context(...)) on the fallible operations
inside read_only_file (around the EitherMmapOrRandomAccessFile::open and/or the
outer closure) to attach the "failed to load CAR at <path>" message while
preserving the original error chain for read_only, AnyCar::new and
EitherMmapOrRandomAccessFile::open.
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
1376e76 to
f98ba71
Compare
f98ba71 to
0a26121
Compare
Summary of changes
Came accross this while investigating #6733 (but this does not fix the issue)
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit