Skip to content

Commit

Permalink
Clarify error language for prefix-conflicting enum values
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 592679725
  • Loading branch information
kupiakos authored and copybara-github committed Dec 21, 2023
1 parent 40ad3fa commit 1ddf033
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 19 additions & 20 deletions src/google/protobuf/descriptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand All @@ -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(
Expand All @@ -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'"
Expand All @@ -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'"
Expand All @@ -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'"
Expand All @@ -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'"
Expand All @@ -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).
Expand All @@ -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'"
Expand All @@ -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'"
Expand All @@ -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) {
Expand Down

0 comments on commit 1ddf033

Please sign in to comment.