diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 82cce7b73abee..690018f5d5245 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -2854,23 +2854,24 @@ bool CommandLineInterface::GeneratePluginOutput( } // Check for errors. - if (!response.error().empty()) { - // Generator returned an error. - *error = response.error(); - return false; - } + bool success = true; if (!EnforceProto3OptionalSupport(plugin_name, response.supported_features(), parsed_files)) { - return false; + success = false; } if (!EnforceEditionsSupport(plugin_name, response.supported_features(), static_cast(response.minimum_edition()), static_cast(response.maximum_edition()), parsed_files)) { - return false; + success = false; + } + if (!response.error().empty()) { + // Generator returned an error. + *error = response.error(); + success = false; } - return true; + return success; } bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) { diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 6a2db03bafda3..8870dabae30f5 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -1854,6 +1854,22 @@ TEST_F(CommandLineInterfaceTest, PluginNoEditionsSupport) { "code generator prefix-gen-plug hasn't been updated to support editions"); } +TEST_F(CommandLineInterfaceTest, PluginErrorAndNoEditionsSupport) { + CreateTempFile("foo.proto", R"schema( + edition = "2023"; + message MockCodeGenerator_Error { } + )schema"); + + SetMockGeneratorTestCase("no_editions"); + Run("protocol_compiler " + "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); + + ExpectErrorSubstring( + "code generator prefix-gen-plug hasn't been updated to support editions"); + ExpectErrorSubstring( + "--plug_out: foo.proto: Saw message type MockCodeGenerator_Error."); +} + TEST_F(CommandLineInterfaceTest, EditionDefaults) { CreateTempFile("google/protobuf/descriptor.proto", google::protobuf::DescriptorProto::descriptor()->file()->DebugString());