Skip to content

fix(protoc): honor --fatal_warnings in encode/decode mode#28033

Open
yashanil98 wants to merge 1 commit into
protocolbuffers:mainfrom
yashanil98:fix/issue-10486-fatal-warnings-encode-decode
Open

fix(protoc): honor --fatal_warnings in encode/decode mode#28033
yashanil98 wants to merge 1 commit into
protocolbuffers:mainfrom
yashanil98:fix/issue-10486-fatal-warnings-encode-decode

Conversation

@yashanil98

Copy link
Copy Markdown

Fixes #10486.

When an input message passed to protoc --encode or --decode is missing required fields, protoc prints warning: Input message is missing required fields: .... That warning was written straight to stderr in EncodeOrDecode and never influenced the exit code, so protoc returned 0 even with --fatal_warnings set, defeating its -Werror-like purpose.

This makes EncodeOrDecode return a non-zero exit when --fatal_warnings is 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_warnings is 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.PartialWithFatalWarnings asserting 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.

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 esrauchg added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jun 16, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jun 16, 2026
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.

protoc cli returns success with --fatal_warnings switch when warnings are detected

2 participants