Skip to content

Commit 986ef8d

Browse files
mkruskal-googlecopybara-github
authored andcommitted
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 1194440 commit 986ef8d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/google/protobuf/compiler/command_line_interface.cc

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

28742874
// Check for errors.
2875-
if (!response.error().empty()) {
2876-
// Generator returned an error.
2877-
*error = response.error();
2878-
return false;
2879-
}
2875+
bool success = true;
28802876
if (!EnforceProto3OptionalSupport(plugin_name, response.supported_features(),
28812877
parsed_files)) {
2882-
return false;
2878+
success = false;
28832879
}
28842880
if (!EnforceEditionsSupport(plugin_name, response.supported_features(),
28852881
static_cast<Edition>(response.minimum_edition()),
28862882
static_cast<Edition>(response.maximum_edition()),
28872883
parsed_files)) {
2888-
return false;
2884+
success = false;
2885+
}
2886+
if (!response.error().empty()) {
2887+
// Generator returned an error.
2888+
*error = response.error();
2889+
success = false;
28892890
}
28902891

2891-
return true;
2892+
return success;
28922893
}
28932894

28942895
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
@@ -1861,6 +1861,22 @@ TEST_F(CommandLineInterfaceTest, PluginNoEditionsSupport) {
18611861
"code generator prefix-gen-plug hasn't been updated to support editions");
18621862
}
18631863

1864+
TEST_F(CommandLineInterfaceTest, PluginErrorAndNoEditionsSupport) {
1865+
CreateTempFile("foo.proto", R"schema(
1866+
edition = "2023";
1867+
message MockCodeGenerator_Error { }
1868+
)schema");
1869+
1870+
SetMockGeneratorTestCase("no_editions");
1871+
Run("protocol_compiler "
1872+
"--proto_path=$tmpdir foo.proto --plug_out=$tmpdir");
1873+
1874+
ExpectErrorSubstring(
1875+
"code generator prefix-gen-plug hasn't been updated to support editions");
1876+
ExpectErrorSubstring(
1877+
"--plug_out: foo.proto: Saw message type MockCodeGenerator_Error.");
1878+
}
1879+
18641880
TEST_F(CommandLineInterfaceTest, EditionDefaults) {
18651881
CreateTempFile("google/protobuf/descriptor.proto",
18661882
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());

0 commit comments

Comments
 (0)