Fix codegen panic on messages containing nested extend blocks#181
Merged
Conversation
`_walk_message` in pb-jelly-gen looked up a non-existent field "extension_type" on `DescriptorProto`. The actual field for nested extensions is named "extension" (number 6), per google/protobuf/descriptor.proto. The bug was dormant because no existing pb-test fixture had a nested `extend` block, but it fires on real-world editions 2023 protos such as upstream google/protobuf/sample_messages_edition.proto, which nest extends inside `MessageSetCorrectExtension*`. The file-level walker (`_walk_file`) already used the correct field name; only the per-message walker was wrong. Adds a regression proto (`pb-test/.../nested_extensions.proto`) containing a message with a nested extend block. Without the fix, running pb_test_gen panics at codegen.rs with `called Option::unwrap() on a None value`; with the fix, codegen and the integration test pass. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The verify_generated_files test (run with VALIDATE=1 in CI) compares generated Rust against .expected snapshots checked into the repo. Adding the new nested_extensions.proto fixture without its snapshot caused CI to fail with NotFound when reading the missing nested_extensions.rs.expected file. Generate the missing snapshot and update lib.rs.expected to declare the new module. Co-authored-by: Cursor <cursoragent@cursor.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
pb-jelly-gen's message walker (_walk_messageincodegen.rs) panicked withcalled Option::unwrap() on a None valuewhenever it encountered a message containing a nestedextendblock.The walker was looking up a field named
"extension_type"onDescriptorProto, but the actual field for nested extensions is named"extension"(number 6) — seegoogle/protobuf/descriptor.proto.get_field("extension_type")returnedNone, and the immediate.unwrap()panicked.The file-level walker (
_walk_file) already used the correct field name, so top-levelextendblocks were unaffected. Only nested extends triggered the bug.Why this surfaced now
The bug was dormant because no existing
pb-testfixture exercised a nestedextendblock. It fires on real-world protos — most notably upstream protobuf v29'sgoogle/protobuf/sample_messages_edition.proto, which nests extends insideMessageSetCorrectExtension*. Anyone pulling protobuf v29 protos into apb-jelly-genbuild hits the panic immediately.Test plan
cd pb-test/pb_test_gen && cargo run— codegen succeedscd pb-test && cargo test— integration tests passpanic on the new fixture, proving the test catches the
regression.