feat(core): implement DeepestErrorFinder for root error detection - #382
Conversation
|
@codewithzubair07 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📝 WalkthroughWalkthroughChangesDeepest error analysis
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant DiagnosticEvents
participant DeepestErrorFinder
participant CallStack
participant DeepestError
DiagnosticEvents->>DeepestErrorFinder: scan call and failure events
DeepestErrorFinder->>CallStack: update depth from fn_call and fn_return
DeepestErrorFinder->>DeepestError: select deepest failure and error code
Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/core/src/decode/chain_analyzer.rs (1)
454-485: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: extract the shared call-stack bookkeeping.
Lines 454-485 duplicate
analyze's loop head (Lines 199-235) verbatim. A small helper (e.g.fn apply_stack_event(stack: &mut Vec<StackFrame>, event, topics) -> boolreturning whether the event was consumed) would keep the two analyzers from drifting, which matters since both rely on identical depth semantics.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/core/src/decode/chain_analyzer.rs` around lines 454 - 485, Extract the duplicated call-stack handling from analyze and the shown event loop into a shared helper, such as apply_stack_event, that accepts the stack, event, and topics and returns whether the event was consumed. Move the fn_call and fn_return logic, including StackFrame depth semantics and address resolution, into that helper, then have both loops invoke it and continue when it returns true.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/core/src/decode/chain_analyzer.rs`:
- Around line 490-491: Update the failure-handling logic around is_failure to
derive depth from the relevant StackFrame's zero-based depth field instead of
using stack.len(). Ensure DeepestError::depth and the reported frame retain the
existing frame-depth semantics, and update the affected depth assertion/comment
expectations from 1 to 0 where they describe top-level failures.
---
Nitpick comments:
In `@crates/core/src/decode/chain_analyzer.rs`:
- Around line 454-485: Extract the duplicated call-stack handling from analyze
and the shown event loop into a shared helper, such as apply_stack_event, that
accepts the stack, event, and topics and returns whether the event was consumed.
Move the fn_call and fn_return logic, including StackFrame depth semantics and
address resolution, into that helper, then have both loops invoke it and
continue when it returns true.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4d6fca50-7601-4b6e-a516-4f8efcb52c3d
📒 Files selected for processing (1)
crates/core/src/decode/chain_analyzer.rs
| if is_failure(event, &topics, &v0.data) { | ||
| let depth = stack.len(); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Off-by-one in depth: frame count vs. frame depth.
StackFrame::depth is assigned stack.len() before the push (Line 476), so a 3-frame stack has depths 0,1,2. Here depth = stack.len() yields 3, contradicting the DeepestError::depth doc ("0 = top-level") and the reported frame at Line 502. This also breaks the assertions at Lines 921 and 944, which expect 2 for a three-deep cascade.
Also, the comment at Line 964 ("Both failures are at depth 1") should read depth 0 once the semantics are corrected.
🐛 Proposed fix: derive depth from the frame, not the frame count
if is_failure(event, &topics, &v0.data) {
- let depth = stack.len();
+ // Use the executing frame's own depth (0 = top-level) so this
+ // matches `StackFrame::depth` and `ChainFrame::depth`.
+ let depth = stack.last().map_or(0, |frame| frame.depth);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if is_failure(event, &topics, &v0.data) { | |
| let depth = stack.len(); | |
| if is_failure(event, &topics, &v0.data) { | |
| // Use the executing frame's own depth (0 = top-level) so this | |
| // matches `StackFrame::depth` and `ChainFrame::depth`. | |
| let depth = stack.last().map_or(0, |frame| frame.depth); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/core/src/decode/chain_analyzer.rs` around lines 490 - 491, Update the
failure-handling logic around is_failure to derive depth from the relevant
StackFrame's zero-based depth field instead of using stack.len(). Ensure
DeepestError::depth and the reported frame retain the existing frame-depth
semantics, and update the affected depth assertion/comment expectations from 1
to 0 where they describe top-level failures.
Summary
Closes #378
Summary by CodeRabbit
New Features
Bug Fixes