fix(protoc): honor --fatal_warnings in encode/decode mode#28033
Open
yashanil98 wants to merge 1 commit into
Open
fix(protoc): honor --fatal_warnings in encode/decode mode#28033yashanil98 wants to merge 1 commit into
yashanil98 wants to merge 1 commit into
Conversation
protoc emits a warning when an input message passed to --encode or --decode is missing required fields, but that warning was printed directly to stderr in EncodeOrDecode and never affected the exit code, so protoc returned 0 even with --fatal_warnings set. Make EncodeOrDecode return a non-zero exit when --fatal_warnings is set and the message is missing required fields, after the output has been written so the behavior matches the compile path. Output and the warning are still produced when --fatal_warnings is not set. Fixes protocolbuffers#10486
esrauchg
approved these changes
Jun 16, 2026
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.
Fixes #10486.
When an input message passed to
protoc --encodeor--decodeis missing required fields, protoc printswarning: Input message is missing required fields: .... That warning was written straight to stderr inEncodeOrDecodeand never influenced the exit code, so protoc returned 0 even with--fatal_warningsset, defeating its-Werror-like purpose.This makes
EncodeOrDecodereturn a non-zero exit when--fatal_warningsis set and the message is missing required fields. The check happens after the output is written, matching the compile path (which also produces its output before failing). When--fatal_warningsis not set, behavior is unchanged: the output and the warning are still produced and the exit code stays 0.A maintainer confirmed this is a valid bug and invited a PR on the issue.
Test: added
EncodeDecodeTest.PartialWithFatalWarningsasserting a non-zero exit (and that the warning is still emitted) when encoding a message with missing required fields under--fatal_warnings../build/tests --gtest_filter='EncodeDecodeTest.'
Result: 18 tests pass, including the new one.