fix: preserve empty error_code on ToolSearchToolResult.ToParam (#317)#338
Open
spor3006 wants to merge 1 commit into
Open
fix: preserve empty error_code on ToolSearchToolResult.ToParam (#317)#338spor3006 wants to merge 1 commit into
spor3006 wants to merge 1 commit into
Conversation
…oParam
ToolSearchToolResultBlock.ToParam() (and its beta twin) constructs a
ToolSearchToolResultErrorParam whose ErrorCode field is tagged
`json:"error_code,omitzero"`. When the response value resolves to the
zero value of ToolSearchToolResultErrorCode (an empty string — typically
because the API returned a code the current SDK version does not list
in its enum, or returned an empty string explicitly), `omitzero` drops
the field entirely. The next request then fails server-side with:
messages.N.content.M.tool_search_tool_result.content
.RequestToolSearchToolResultError.error_code: Field required
Use the param package's SetExtraFields escape hatch to force the field
to be emitted with the original raw string value when the typed value
is zero. This is the smallest correct fix and avoids touching the
generated types, which would be regenerated away.
Adds two regression tests covering both a recognized error_code and the
empty-string case that previously regressed.
Fixes anthropics#317
Signed-off-by: Sparshal Kothari <41056517+spor3006@users.noreply.github.com>
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.
Summary
ToolSearchToolResultBlock.ToParam()and its beta twinBetaToolSearchToolResultBlock.ToParam()build aToolSearchToolResultErrorParamwhoseErrorCodeis taggedjson:"error_code,omitzero". When the response value resolves to the zero value ofToolSearchToolResultErrorCode(empty string — e.g. the API returned an enum value the SDK doesn't list yet, or returnederror_code: ""),omitzerodrops the field. The next request then fails server-side with:This is the same class of
ToParamround-trip bug as #242, but isolated to the tool-search error variant. Reported in #317 with a working raw-JSON passthrough workaround.Fix
In the handwritten helpers in
messageutil.goandbetamessageutil.go, when the typedErrorCodeis the zero value, use the param package'sSetExtraFieldsescape hatch (documented atpackages/param/param.go:146-159) to force the field to marshal with the original raw value from the response. Known/recognized codes continue to flow through the typed field exactly as before.This deliberately:
*messageutil.gohelpers thatCONTRIBUTING.mdalready designates as the place for this kind of manual fix.betamessageutil.gobecause the bug is identical there.Test
Adds two subtests under
TestContentBlockUnionToParam:ToolSearchToolResultBlock error preserves known error_code— guards the existing code path so it doesn't regress.ToolSearchToolResultBlock error preserves empty error_code— regression test for ToolSearchToolResultBlock.ToParam() drops required error_code field via omitzero #317. Fails onmain, passes on this branch.Both tests round-trip the marshaled JSON to assert
content.error_codeis actually present in the wire payload (not just on the typed struct), which is what the API enforces.Test plan
./scripts/lintpassesgo test -run TestContentBlockUnionToParam ./...passesmainwithout the fix and passes with itFixes #317
Related to #242