Skip to content

fix: surface cause details in error messages#139

Merged
tuannvm merged 2 commits intotuannvm:mainfrom
hampsterx:fix/improve-error-messages
Apr 7, 2026
Merged

fix: surface cause details in error messages#139
tuannvm merged 2 commits intotuannvm:mainfrom
hampsterx:fix/improve-error-messages

Conversation

@hampsterx
Copy link
Copy Markdown
Contributor

@hampsterx hampsterx commented Mar 29, 2026

Summary

  • ToolExecutionError and CommandExecutionError now append the underlying cause's message when available
  • Previously errors like Failed to execute tool "review": Failed to execute code review gave no actionable detail
  • Now produces e.g. Failed to execute tool "review": Failed to execute code review (model not found)
  • Deduplicates: if the cause message matches the wrapper message, it's not repeated

Addresses the error message concern raised in #91.

Test plan

  • Build passes (npm run build)
  • 70/71 tests pass (1 pre-existing timeout in index.test.ts unrelated to this change)
  • No new dependencies

Summary by CodeRabbit

Bug Fixes

  • Enhanced error messages to include additional context from underlying causes. When an error has a related cause with a distinct message, that information is now appended to the primary error message, providing users with more detailed insights into what went wrong during command or tool execution.

ToolExecutionError and CommandExecutionError were swallowing the
underlying cause, producing generic messages like "Failed to execute
tool review: Failed to execute code review" with no actionable detail.

Now appends the cause's message when available, e.g.:
"Failed to execute tool review: Failed to execute code review (model not found)"

Closes tuannvm#91 (error message portion)

Signed-off-by: TiM <tim.vdh@gmail.not>
Signed-off-by: TiM <tim@nuimarkets.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Walkthrough

The ToolExecutionError and CommandExecutionError classes in src/errors.ts were updated to include additional context from the cause parameter when constructing error messages. Now, when a cause is provided and is an Error with a non-empty message differing from the primary message, it is appended to the error message string.

Changes

Cohort / File(s) Summary
Error Message Enhancement
src/errors.ts
Updated ToolExecutionError and CommandExecutionError constructors to append cause message details (${causeMsg}) to error messages when the cause is an Error with a non-empty, distinct message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hops with glee, for errors now speak true,
With cause details appended, debugging's a breeze, it's true!
No more hidden whispers in the stack's dark hole,
The rabbit's fixed the messages—now debugging's whole! 🌕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'fix: surface cause details in error messages' clearly and specifically describes the main change—enhancing error messages by including cause details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hampsterx
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/errors.ts (1)

20-22: LGTM! Consider extracting shared logic.

The implementation is correct and mirrors ToolExecutionError. Lines 20-21 are identical to lines 7-8. For a file this small, the duplication is acceptable, but if you prefer DRY:

♻️ Optional: Extract helper function
+function formatCauseDetail(message: string, cause?: unknown): string {
+  const causeMsg = cause instanceof Error ? cause.message : '';
+  return causeMsg && causeMsg !== message ? ` (${causeMsg})` : '';
+}
+
 export class ToolExecutionError extends Error {
   constructor(
     public readonly toolName: string,
     message: string,
     public readonly cause?: unknown
   ) {
-    const causeMsg = cause instanceof Error ? cause.message : '';
-    const detail = causeMsg && causeMsg !== message ? ` (${causeMsg})` : '';
-    super(`Failed to execute tool "${toolName}": ${message}${detail}`);
+    super(`Failed to execute tool "${toolName}": ${message}${formatCauseDetail(message, cause)}`);
     this.name = 'ToolExecutionError';
   }
 }

 export class CommandExecutionError extends Error {
   constructor(
     public readonly command: string,
     message: string,
     public readonly cause?: unknown
   ) {
-    const causeMsg = cause instanceof Error ? cause.message : '';
-    const detail = causeMsg && causeMsg !== message ? ` (${causeMsg})` : '';
-    super(`Command execution failed for "${command}": ${message}${detail}`);
+    super(`Command execution failed for "${command}": ${message}${formatCauseDetail(message, cause)}`);
     this.name = 'CommandExecutionError';
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/errors.ts` around lines 20 - 22, Extract the duplicate cause/message
formatting into a small helper (e.g., formatCauseDetail) and use it in both
places where the lines are identical (the current constructor that builds the
message and the ToolExecutionError constructor) so you avoid repeating the logic
that computes causeMsg and detail; implement the helper to accept (cause,
message) and return the trailing detail string (or empty string) and call it
when constructing the super(...) message in both constructors.
🤖 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/errors.ts`:
- Around line 20-22: Extract the duplicate cause/message formatting into a small
helper (e.g., formatCauseDetail) and use it in both places where the lines are
identical (the current constructor that builds the message and the
ToolExecutionError constructor) so you avoid repeating the logic that computes
causeMsg and detail; implement the helper to accept (cause, message) and return
the trailing detail string (or empty string) and call it when constructing the
super(...) message in both constructors.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d5a15c3d-84ab-46dd-b581-69ff0ce07b69

📥 Commits

Reviewing files that changed from the base of the PR and between 00b6bf6 and c0e76df.

📒 Files selected for processing (1)
  • src/errors.ts

@tuannvm tuannvm merged commit a1b042c into tuannvm:main Apr 7, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants