From 1ddf0337113b4ac34bc9b2f4f1b099017261bd67 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Wed, 20 Dec 2023 15:57:34 -0800 Subject: [PATCH] Clarify error language for prefix-conflicting enum values PiperOrigin-RevId: 592679725 --- src/google/protobuf/descriptor.cc | 2 +- src/google/protobuf/descriptor_unittest.cc | 39 +++++++++++----------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 004be51c3bdc..ff373708b6d3 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -6710,7 +6710,7 @@ void DescriptorBuilder::CheckEnumValueUniqueness( return absl::StrFormat( "Enum name %s has the same name as %s if you ignore case and strip " "out the enum name prefix (if any). (If you are using allow_alias, " - "please assign the same numeric value to both enums.)", + "please assign the same number to each enum value name.)", value->name(), insert_result.first->second->name()); }; // There are proto2 enums out there with conflicting names, so to preserve diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 703fb77861f5..7745313ff606 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -6653,8 +6653,8 @@ TEST_F(ValidationErrorTest, Proto3EnumValuesConflictWithDifferentCasing) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto2'" @@ -6666,8 +6666,8 @@ TEST_F(ValidationErrorTest, Proto3EnumValuesConflictWithDifferentCasing) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); // Not an error because both enums are mapped to the same value. BuildFile( @@ -6693,8 +6693,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOO_ENUM_BAZ " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric value " - "to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6706,8 +6706,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOOENUM_BAZ " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric value " - "to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6719,8 +6719,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR__BAZ: NAME: Enum name BAR__BAZ has the same name as " "FOO_ENUM_BAR_BAZ if you ignore case and strip out the enum name prefix " - "(if any). (If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(if any). (If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6732,8 +6732,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR_BAZ: NAME: Enum name BAR_BAZ has the same name as " "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name prefix " - "(if any). (If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(if any). (If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto2'" @@ -6745,8 +6745,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR_BAZ: NAME: Enum name BAR_BAZ has the same name as " "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name prefix " - "(if any). (If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(if any). (If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); // This isn't an error because the underscore will cause the PascalCase to // differ by case (BarBaz vs. Barbaz). @@ -6772,8 +6772,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictLegacyBehavior) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6788,8 +6788,7 @@ TEST_F(ValidationErrorTest, EnumValuesConflictLegacyBehavior) { "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name " "prefix " "(if any). (If you are using allow_alias, please assign the same " - "numeric " - "value to both enums.)\n"); + "number to each enum value name.)\n"); BuildFileWithWarnings( "syntax: 'proto2'" @@ -6802,8 +6801,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictLegacyBehavior) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); } TEST_F(ValidationErrorTest, MapEntryConflictsWithOneof) {