Skip to content

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

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

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
Contributor

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.

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

runzw commented Jun 29, 2026

Copy link
Copy Markdown
Member

Rerunning copybara check

@esrauchg esrauchg added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jul 27, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jul 27, 2026
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
@tonyliaoss
tonyliaoss force-pushed the fix/issue-10486-fatal-warnings-encode-decode branch from f1c500b to d0bb423 Compare August 10, 2026 21:06
@tonyliaoss tonyliaoss added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Aug 10, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Aug 10, 2026
copybara-service Bot pushed a commit that referenced this pull request Aug 17, 2026
This reduces the cost of including the headers.

COPYBARA_INTEGRATE_REVIEW=#28033 from yashanil98:fix/issue-10486-fatal-warnings-encode-decode d0bb423
FUTURE_COPYBARA_INTEGRATE_REVIEW=#28033 from yashanil98:fix/issue-10486-fatal-warnings-encode-decode d0bb423
PiperOrigin-RevId: 964912794
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

4 participants