Skip to content

Commit 9a37881

Browse files
Always report plugin support errors from protoc.
If a plugin doesn't support a feature used by a proto file, we can't trust any errors reported by that plugin. We should always report these types of errors first. There could be cases where the plugin doesn't correctly specify its support when it hits an error though, so we should *also* report any plugin errors to avoid masking them. PiperOrigin-RevId: 639984803
1 parent f61d89c commit 9a37881

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/google/protobuf/compiler/command_line_interface.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,23 +2854,24 @@ bool CommandLineInterface::GeneratePluginOutput(
28542854
}
28552855

28562856
// Check for errors.
2857-
if (!response.error().empty()) {
2858-
// Generator returned an error.
2859-
*error = response.error();
2860-
return false;
2861-
}
2857+
bool success = true;
28622858
if (!EnforceProto3OptionalSupport(plugin_name, response.supported_features(),
28632859
parsed_files)) {
2864-
return false;
2860+
success = false;
28652861
}
28662862
if (!EnforceEditionsSupport(plugin_name, response.supported_features(),
28672863
static_cast<Edition>(response.minimum_edition()),
28682864
static_cast<Edition>(response.maximum_edition()),
28692865
parsed_files)) {
2870-
return false;
2866+
success = false;
2867+
}
2868+
if (!response.error().empty()) {
2869+
// Generator returned an error.
2870+
*error = response.error();
2871+
success = false;
28712872
}
28722873

2873-
return true;
2874+
return success;
28742875
}
28752876

28762877
bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) {

src/google/protobuf/compiler/command_line_interface_unittest.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,22 @@ TEST_F(CommandLineInterfaceTest, PluginNoEditionsSupport) {
18541854
"code generator prefix-gen-plug hasn't been updated to support editions");
18551855
}
18561856

1857+
TEST_F(CommandLineInterfaceTest, PluginErrorAndNoEditionsSupport) {
1858+
CreateTempFile("foo.proto", R"schema(
1859+
edition = "2023";
1860+
message MockCodeGenerator_Error { }
1861+
)schema");
1862+
1863+
SetMockGeneratorTestCase("no_editions");
1864+
Run("protocol_compiler "
1865+
"--proto_path=$tmpdir foo.proto --plug_out=$tmpdir");
1866+
1867+
ExpectErrorSubstring(
1868+
"code generator prefix-gen-plug hasn't been updated to support editions");
1869+
ExpectErrorSubstring(
1870+
"--plug_out: foo.proto: Saw message type MockCodeGenerator_Error.");
1871+
}
1872+
18571873
TEST_F(CommandLineInterfaceTest, EditionDefaults) {
18581874
CreateTempFile("google/protobuf/descriptor.proto",
18591875
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());

0 commit comments

Comments
 (0)