From 87f24e47595ef5e382949346e50a81150d35c230 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Tue, 13 Sep 2022 16:32:48 -0400 Subject: [PATCH] add allowed ranges to error messages --- src/google/protobuf/descriptor.cc | 18 ++++++++---------- src/google/protobuf/descriptor_unittest.cc | 16 ++++++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index ddebcf6184..0e43bc3af6 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -7683,7 +7683,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError("Value out of range for int32 option \"" + + return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" + option_field->full_name() + "\"."); } else { SetInt32(option_field->number(), @@ -7693,7 +7693,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } else if (uninterpreted_option_->has_negative_int_value()) { if (uninterpreted_option_->negative_int_value() < static_cast(std::numeric_limits::min())) { - return AddValueError("Value out of range for int32 option \"" + + return AddValueError("Value out of range, -2,147,483,648 to 2,147,483,647, for int32 option \"" + option_field->full_name() + "\"."); } else { SetInt32(option_field->number(), @@ -7701,7 +7701,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( option_field->type(), unknown_fields); } } else { - return AddValueError("Value must be integer for int32 option \"" + + return AddValueError("Value must be integer, from -2,147,483,648 to 2,147,483,647, for int32 option \"" + option_field->full_name() + "\"."); } break; @@ -7710,7 +7710,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError("Value out of range for int64 option \"" + + return AddValueError("Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" + option_field->full_name() + "\"."); } else { SetInt64(option_field->number(), @@ -7722,7 +7722,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError("Value must be integer for int64 option \"" + + return AddValueError("Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, for int64 option \"" + option_field->full_name() + "\"."); } break; @@ -7731,7 +7731,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > std::numeric_limits::max()) { - return AddValueError("Value out of range for uint32 option \"" + + return AddValueError("Value out of range, 0 to 4,294,967,295, for uint32 option \"" + option_field->name() + "\"."); } else { SetUInt32(option_field->number(), @@ -7740,8 +7740,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } } else { return AddValueError( - "Value must be non-negative integer for uint32 " - "option \"" + + "Value must be integer, from 0 to 4,294,967,295, for uint32 option \"" + option_field->full_name() + "\"."); } break; @@ -7753,8 +7752,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( option_field->type(), unknown_fields); } else { return AddValueError( - "Value must be non-negative integer for uint64 " - "option \"" + + "Value must be integer, from 0 to 18,446,744,073,709,551,615, for uint64 option \"" + option_field->full_name() + "\"."); } break; diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index a2900454f6..33d4299fb6 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -5557,7 +5557,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfPositiveRange) { " positive_int_value: 0x80000000 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, " "for int32 option \"foo\".\n"); } @@ -5574,7 +5574,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfNegativeRange) { " negative_int_value: -0x80000001 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2,147,483,648 to 2,147,483,647, " "for int32 option \"foo\".\n"); } @@ -5590,7 +5590,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueIsNotPositiveInt) { " is_extension: true } " " string_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -2,147,483,648 to 2,147,483,647, " "for int32 option \"foo\".\n"); } @@ -5608,7 +5608,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueOutOfRange) { "} " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, " "for int64 option \"foo\".\n"); } @@ -5624,7 +5624,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueIsNotPositiveInt) { " is_extension: true } " " identifier_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, " "for int64 option \"foo\".\n"); } @@ -5640,7 +5640,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueOutOfRange) { " is_extension: true } " " positive_int_value: 0x100000000 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range, 0 to 4,294,967,295, " "for uint32 option \"foo\".\n"); } @@ -5656,7 +5656,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueIsNotPositiveInt) { " is_extension: true } " " double_value: -5.6 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 4,294,967,295, " "for uint32 option \"foo\".\n"); } @@ -5672,7 +5672,7 @@ TEST_F(ValidationErrorTest, UInt64OptionValueIsNotPositiveInt) { " is_extension: true } " " negative_int_value: -5 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 18,446,744,073,709,551,615, " "for uint64 option \"foo\".\n"); }