Skip to content

protomodule: return error instead of panicking on non-message args to proto.merge#149

Open
LeSingh1 wants to merge 1 commit into
stripe:trunkfrom
LeSingh1:fix-merge-panic
Open

protomodule: return error instead of panicking on non-message args to proto.merge#149
LeSingh1 wants to merge 1 commit into
stripe:trunkfrom
LeSingh1:fix-merge-panic

Conversation

@LeSingh1
Copy link
Copy Markdown

The proto.merge builtin used unchecked type assertions on its two arguments, so passing any non-proto-message value from Starlark code would panic the host Go program instead of producing a regular Starlark error. Since proto.merge is exposed directly to user configs, this is reachable from any config that calls it with the wrong type, for example by accident or while iterating on a script.

The fix replaces the assertions with checked conversions that return a normal error, matching the style already used in proto.decode_json, proto.decode_text, and wantSingleProtoMessage in the same file. The error format mirrors those callers ("proto.merge: for parameter N: got X, want proto.Message") so it slots in with the existing error vocabulary.

Added a TestProtoMergeNonMessage test that exercises both argument positions with a Starlark string and verifies the expected error text. The existing TestProtoMergeDiffTypes only covered the case where both args were proto messages of different types, so this new test fills the gap on the non-message path.

Verified with go build ./... and go test on the packages that build outside of Bazel locally. The protomodule unit tests need the bazel-generated test protos to compile, so the new test was written to match the existing TestProtoMergeDiffTypes pattern that CI already runs.

… proto.merge

proto.merge used unchecked type assertions on its arguments, which would
panic if either was not a *protoMessage. Since proto.merge is a builtin
exposed to user Starlark code, this means any config could crash the host
program with a Go panic instead of producing a Starlark error.

Replace the assertions with checked conversions that return a regular
error matching the style of proto.decode_json and proto.decode_text.
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented May 19, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented May 19, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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