fix: validate PROTO/ENUM wire kind in literal cast plugins#164
Conversation
FormatProtoAsCast and FormatEnumAsCast now call requireStringWire after NULL handling so malformed structpb kinds return ErrUnknownType instead of emitting invalid SQL. Fixes #156. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request adds validation checks in common.go to ensure that Proto and Enum values are represented as string wire types before formatting them as casts, using requireStringWire in FormatProtoAsCast and FormatEnumAsCast. It also adds unit tests in common_test.go to verify that non-string wire types are correctly rejected with ErrUnknownType. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
apstndb
left a comment
There was a problem hiding this comment.
LGTM. Calling requireStringWire after the IsNull guard in FormatProtoAsCast/FormatEnumAsCast is the right placement, and returning ErrUnknownType for non-string PROTO/ENUM wire matches how validateScalarWire already classifies those codes (both route to requireStringWire), so the slow/scalar paths stay consistent. Previously a bool/number wire would silently produce CAST(b"" AS ...) / CAST( AS ...) invalid SQL, so this is a clear correctness fix. The table test covers bool and number kinds for both PROTO and ENUM via LiteralFormatConfig. No issues found.
Summary
requireStringWireinFormatProtoAsCastandFormatEnumAsCastafter NULL handling so malformedstructpbkinds returnErrUnknownTypeinstead of emitting invalid SQL.LiteralFormatConfig.Fixes #156.
Test plan
make checkTestFormatProtoEnumCastRejectsNonStringWirecovers PROTO/ENUM bool and number wire kindsMade with Cursor