Skip to content

feat(tools): add ToolError for expected failures with structured fields - #48

Merged
offendingcommit merged 1 commit into
mainfrom
feat/tool-error
Oct 30, 2026
Merged

offendingcommit merged 1 commit into
mainfrom
feat/tool-error

Conversation

@offendingcommit

Copy link
Copy Markdown
Owner

Problem

When a @tool handler raised, the result kept only "<tool> failed: <exception>", and the kit logged a traceback even for an expected refusal. memory-sync attaches fields to its errors on 158 paths, among them path, sha, rolled_back, rollback_errors, committed, pending_push and error_kind. So it encodes its own JSON results instead of using the kit.

Change

  • New exported ToolError(message, **fields). When a handler raises it, the result is {"success": false, "error": message, **fields}, byte-identical to memory-sync's private _err. It is logged as a warning (<tool>: refused) without a traceback.
  • Fields named success or error raise ValueError.
  • Other exceptions are unchanged.
  • README "Handler contract" updated.

Proof

  • just test OK.
  • test_tool_error_keeps_its_fields_and_logs_no_traceback asserts the exact bytes. Deleting the except ToolError branch fails it.

First step of moving memory-sync onto the kit fully.

https://claude.ai/code/session_01B6XeAU5Gn7ZaLQJVSg4AKC

A @tool handler that raised lost everything but its text: the kit
encoded "<tool> failed: <exception>" and logged a traceback even for an
expected refusal. Plugins that need codes or state in the result
(memory-sync sends path, rolled_back, committed, pending_push and more
on 158 error paths) kept their own JSON encoders instead.

raise ToolError(message, **fields) now encodes
{"success": false, "error": message, **fields}, byte-for-byte the shape
those private encoders produce, and logs a warning without a traceback.
Fields may not set success or error.

Claude-Session: https://claude.ai/code/session_01B6XeAU5Gn7ZaLQJVSg4AKC
@offendingcommit
offendingcommit merged commit a725be6 into main Oct 30, 2026
6 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.

1 participant