Repository navigation
feat(tools): add ToolError for expected failures with structured fields - #48
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
@toolhandler 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 thempath,sha,rolled_back,rollback_errors,committed,pending_pushanderror_kind. So it encodes its own JSON results instead of using the kit.Change
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.successorerrorraiseValueError.Proof
just testOK.test_tool_error_keeps_its_fields_and_logs_no_tracebackasserts the exact bytes. Deleting theexcept ToolErrorbranch fails it.First step of moving memory-sync onto the kit fully.
https://claude.ai/code/session_01B6XeAU5Gn7ZaLQJVSg4AKC