Skip to content

fix(tools): introduce ToolInputError to classify expected tool failures - #383

Merged
dcramer merged 1 commit into
mainfrom
jr/fix-editfile-enoent-handling
May 20, 2026
Merged

dcramer merged 1 commit into
mainfrom
jr/fix-editfile-enoent-handling

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The tool error handler (handleToolExecutionError) sent all non-MCP tool errors to Sentry via logException, even when the error was caused by invalid model input — missing files, bad regex, ambiguous edits, path traversal. This created noisy alerts for expected conditions like JUNIOR-2Q.

This introduces ToolInputError as the single classification mechanism for expected model/user-caused tool failures. Domain code throws ToolInputError at the source where it knows the failure is input-caused, not a system error. The global error handler respects this: no logException, no Sentry noise.

Architecture

Domain code throws ToolInputError  → handleToolExecutionError → logWarn only → rethrow → Pi tool_error
Domain code throws Error (system)  → handleToolExecutionError → logException (Sentry) → rethrow
MCP tool returns isError           → McpToolError             → logWarn only → rethrow → Pi tool_error

No ad-hoc error-type catches at the executor level. The domain function that creates the error owns the classification.

Changes

New:

  • tool-input-error.ts — ToolInputError class

Error handler:

  • tool-error-handler.ts — skip logException for ToolInputError; replace getMcpAwareErrorType with getToolErrorType() covering both MCP and input error classification

Domain sources that now throw ToolInputError:

  • edit-file.ts — ENOENT on fs.readFile → ToolInputError("File not found: ...")
  • text-edits.ts — all validation (not found, ambiguous, overlap, no-op, empty oldText, bad newText)
  • file-utils.ts — workspace path traversal
  • list-dir.ts — not-a-directory
  • grep.ts — invalid regex pattern
  • sandbox.ts — missing required arguments (path, edits, pattern, command)

What stays as system errors (still reports to Sentry):

  • Sandbox API failures (throwSandboxOperationError)
  • Slack API errors
  • Network/connection failures
  • Non-ENOENT filesystem errors
  • unsupported sandbox tool (config error)

Tests

  • tool-error-handler.test.ts (new) — system errors call logException; ToolInputError and McpToolError do not
  • file-tools.test.ts — ToolInputError for ambiguous edits, text not found, path traversal, invalid regex, file-as-directory
  • sandbox-executor.test.ts — editFile on missing path throws ToolInputError

Verification

  • pnpm typecheck ✅
  • 51/51 tests passing ✅
  • Lint + prettier ✅

Fixes JUNIOR-2Q

Requested-By: David Cramer

@vercel

vercel Bot commented May 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment May 20, 2026 6:48pm

Request Review

@sentry-junior
sentry-junior Bot force-pushed the jr/fix-editfile-enoent-handling branch from be7ecdb to 30f21be Compare May 20, 2026 18:42
@sentry-junior sentry-junior Bot changed the title fix(sandbox): handle ENOENT gracefully in editFile executor fix(tools): introduce ToolInputError to classify expected tool failures May 20, 2026
The tool error handler sent all non-MCP tool errors to Sentry via
logException, even when the error was caused by invalid model input
(missing files, bad regex, ambiguous edits, path traversal). This
created noisy alerts for expected conditions.

Introduce ToolInputError — a semantic error class for model/user-caused
tool failures. The global tool error handler now skips logException for
both McpToolError and ToolInputError, logging warnings instead.

Domain code throws ToolInputError at source where it knows the failure
is expected input, not a system error:
- edit-file: missing file (ENOENT)
- text-edits: all validation (not found, ambiguous, overlap, no-op)
- file-utils: workspace path traversal
- list-dir: not-a-directory
- grep: invalid regex pattern
- sandbox executor: missing required arguments

System errors (sandbox API failures, Slack errors, network issues) still
propagate as normal Errors and report to Sentry.

Fixes JUNIOR-2Q

Co-Authored-By: Claude (anthropic/claude-opus-4.6) <[email protected]>
@sentry-junior
sentry-junior Bot force-pushed the jr/fix-editfile-enoent-handling branch from 30f21be to 76a235f Compare May 20, 2026 18:47
@dcramer
dcramer merged commit 5440d7e into main May 20, 2026
16 checks passed
@dcramer
dcramer deleted the jr/fix-editfile-enoent-handling branch May 20, 2026 18:56

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 76a235fc Deployed May 20, 2026 by vercel[bot]
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.

1 participant