Skip to content

Commit f1591a4

Browse files
authored
Remove usage of google::protobuf::util::error. (#59)
This is needed to be compatible with protobuf 3.16.0.
1 parent 988796c commit f1591a4

17 files changed

+56
-61
lines changed

repositories.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ cc_library(
9292
build_file_content = BUILD,
9393
)
9494

95-
PROTOBUF_COMMIT = "3.15.5" # Mar 04, 2021
96-
PROTOBUF_SHA256 = "bc3dbf1f09dba1b2eb3f2f70352ee97b9049066c9040ce0c9b67fb3294e91e4b"
95+
PROTOBUF_COMMIT = "3.16.0" # Mar 04, 2021
96+
PROTOBUF_SHA256 = "7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5"
9797

9898
RULES_PROTO_SHA = "97d8af4dc474595af3900dd85cb3a29ad28cc313" # Oct 31, 2019
9999
RULES_PROTO_SHA256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208"

src/include/grpc_transcoding/request_message_translator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class RequestMessageTranslator : public MessageStream {
135135
class StatusErrorListener
136136
: public ::google::protobuf::util::converter::ErrorListener {
137137
public:
138-
StatusErrorListener() : status_(::google::protobuf::util::Status::OK) {}
138+
StatusErrorListener() {}
139139
virtual ~StatusErrorListener() {}
140140

141141
::google::protobuf::util::Status status() const { return status_; }

src/message_reader.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ std::unique_ptr<pbio::ZeroCopyInputStream> MessageReader::NextMessage() {
9292
finished_ = in_->Finished();
9393
if (finished_ && in_->BytesAvailable() != 0) {
9494
status_ = google::protobuf::util::Status(
95-
google::protobuf::util::error::INTERNAL,
95+
google::protobuf::util::StatusCode::kInternal,
9696
"Incomplete gRPC frame header received");
9797
}
9898
return nullptr;
@@ -107,7 +107,7 @@ std::unique_ptr<pbio::ZeroCopyInputStream> MessageReader::NextMessage() {
107107

108108
if (delimiter_[0] != 0) {
109109
status_ = google::protobuf::util::Status(
110-
google::protobuf::util::error::INTERNAL,
110+
google::protobuf::util::StatusCode::kInternal,
111111
"Unsupported gRPC frame flag: " + std::to_string(delimiter_[0]));
112112
return nullptr;
113113
}
@@ -119,7 +119,7 @@ std::unique_ptr<pbio::ZeroCopyInputStream> MessageReader::NextMessage() {
119119
if (in_->BytesAvailable() < static_cast<pb::int64>(current_message_size_)) {
120120
if (in_->Finished()) {
121121
status_ = google::protobuf::util::Status(
122-
google::protobuf::util::error::INTERNAL,
122+
google::protobuf::util::StatusCode::kInternal,
123123
"Incomplete gRPC frame expected size: " +
124124
std::to_string(current_message_size_) + " actual size: " +
125125
std::to_string(in_->BytesAvailable()));

src/request_message_translator.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ void RequestMessageTranslator::StatusErrorListener::InvalidName(
133133
const ::google::protobuf::util::converter::LocationTrackerInterface& loc,
134134
internal::string_view unknown_name, internal::string_view message) {
135135
status_ = ::google::protobuf::util::Status(
136-
::google::protobuf::util::error::INVALID_ARGUMENT,
136+
::google::protobuf::util::StatusCode::kInvalidArgument,
137137
loc.ToString() + ": " + std::string(message));
138138
}
139139

140140
void RequestMessageTranslator::StatusErrorListener::InvalidValue(
141141
const ::google::protobuf::util::converter::LocationTrackerInterface& loc,
142142
internal::string_view type_name, internal::string_view value) {
143143
status_ = ::google::protobuf::util::Status(
144-
::google::protobuf::util::error::INVALID_ARGUMENT,
144+
::google::protobuf::util::StatusCode::kInvalidArgument,
145145
loc.ToString() + ": invalid value " + std::string(value) + " for type " +
146146
std::string(type_name));
147147
}
@@ -150,7 +150,7 @@ void RequestMessageTranslator::StatusErrorListener::MissingField(
150150
const ::google::protobuf::util::converter::LocationTrackerInterface& loc,
151151
internal::string_view missing_name) {
152152
status_ = ::google::protobuf::util::Status(
153-
::google::protobuf::util::error::INVALID_ARGUMENT,
153+
::google::protobuf::util::StatusCode::kInvalidArgument,
154154
loc.ToString() + ": missing field " + std::string(missing_name));
155155
}
156156

src/request_stream_translator.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace transcoding {
2828

2929
namespace pb = google::protobuf;
3030
namespace pbutil = google::protobuf::util;
31-
namespace pberr = google::protobuf::util::error;
3231
namespace pbconv = google::protobuf::util::converter;
3332

3433
RequestStreamTranslator::RequestStreamTranslator(
@@ -67,7 +66,7 @@ RequestStreamTranslator* RequestStreamTranslator::StartObject(
6766
}
6867
if (depth_ == 0) {
6968
// In depth_ == 0 case we expect only StartList()
70-
status_ = pbutil::Status(pberr::INVALID_ARGUMENT,
69+
status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument,
7170
"Expected an array instead of an object");
7271
return this;
7372
}
@@ -89,7 +88,7 @@ RequestStreamTranslator* RequestStreamTranslator::EndObject() {
8988
--depth_;
9089
if (depth_ < 1) {
9190
status_ =
92-
pbutil::Status(pberr::INVALID_ARGUMENT, "Mismatched end of object.");
91+
pbutil::Status(pbutil::StatusCode::kInvalidArgument, "Mismatched end of object.");
9392
return this;
9493
}
9594
translator_->Input().EndObject();
@@ -131,7 +130,7 @@ RequestStreamTranslator* RequestStreamTranslator::EndList() {
131130
--depth_;
132131
if (depth_ < 0) {
133132
status_ =
134-
pbutil::Status(pberr::INVALID_ARGUMENT, "Mismatched end of array.");
133+
pbutil::Status(pbutil::StatusCode::kInvalidArgument, "Mismatched end of array.");
135134
return this;
136135
}
137136
if (depth_ == 0) {
@@ -252,7 +251,7 @@ void RequestStreamTranslator::EndMessageTranslator() {
252251
} else {
253252
// This shouldn't happen unless something like StartList(), StartObject(),
254253
// EndList() has been called
255-
status_ = pbutil::Status(pberr::INVALID_ARGUMENT, "Invalid object");
254+
status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument, "Invalid object");
256255
}
257256
translator_.reset();
258257
}
@@ -265,7 +264,7 @@ void RequestStreamTranslator::RenderData(internal::string_view name,
265264
}
266265
if (depth_ == 0) {
267266
// In depth_ == 0 case we expect only a StartList()
268-
status_ = pbutil::Status(pberr::INVALID_ARGUMENT,
267+
status_ = pbutil::Status(pbutil::StatusCode::kInvalidArgument,
269268
"Expected an array instead of a scalar value.");
270269
} else if (depth_ == 1) {
271270
// This means we have an array of scalar values. This can happen if the HTTP

src/response_to_json_translator.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool ResponseToJsonTranslator::TranslateMessage(
107107
// output JSON with a '['.
108108
if (!WriteChar(&json_stream, '[')) {
109109
status_ = ::google::protobuf::util::Status(
110-
::google::protobuf::util::error::INTERNAL,
110+
::google::protobuf::util::StatusCode::kInternal,
111111
"Failed to build the response message.");
112112
return false;
113113
}
@@ -116,7 +116,7 @@ bool ResponseToJsonTranslator::TranslateMessage(
116116
// For streaming calls add a ',' before each message except the first.
117117
if (!WriteChar(&json_stream, ',')) {
118118
status_ = ::google::protobuf::util::Status(
119-
::google::protobuf::util::error::INTERNAL,
119+
::google::protobuf::util::StatusCode::kInternal,
120120
"Failed to build the response message.");
121121
return false;
122122
}

src/type_helper.cc

+6-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
namespace pbutil = ::google::protobuf::util;
2929
namespace pbconv = ::google::protobuf::util::converter;
30-
namespace pberr = ::google::protobuf::util::error;
3130

3231
namespace google {
3332
namespace grpc {
@@ -63,7 +62,7 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
6362
}
6463
return pbutil::Status();
6564
} else {
66-
return pbutil::Status(pberr::NOT_FOUND,
65+
return pbutil::Status(pbutil::StatusCode::kNotFound,
6766
"Type '" + type_url + "' cannot be found.");
6867
}
6968
}
@@ -78,7 +77,7 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
7877
}
7978
return pbutil::Status();
8079
} else {
81-
return pbutil::Status(pberr::NOT_FOUND,
80+
return pbutil::Status(pbutil::StatusCode::kNotFound,
8281
"Enum '" + type_url + "' cannot be found.");
8382
}
8483
}
@@ -159,7 +158,7 @@ pbutil::Status TypeHelper::ResolveFieldPath(
159158
// Find the field by name in the current type
160159
auto field = Info()->FindField(current_type, field_names[i]);
161160
if (nullptr == field) {
162-
return pbutil::Status(pberr::INVALID_ARGUMENT,
161+
return pbutil::Status(pbutil::StatusCode::kInvalidArgument,
163162
"Could not find field \"" + field_names[i] +
164163
"\" in the type \"" + current_type->name() +
165164
"\".");
@@ -170,22 +169,22 @@ pbutil::Status TypeHelper::ResolveFieldPath(
170169
// If this is not the last field in the path, it must be a message
171170
if (google::protobuf::Field::TYPE_MESSAGE != field->kind()) {
172171
return pbutil::Status(
173-
pberr::INVALID_ARGUMENT,
172+
pbutil::StatusCode::kInvalidArgument,
174173
"Encountered a non-leaf field \"" + field->name() +
175174
"\" that is not a message while parsing a field path");
176175
}
177176

178177
// Update the type of the current message
179178
current_type = Info()->GetTypeByTypeUrl(field->type_url());
180179
if (nullptr == current_type) {
181-
return pbutil::Status(pberr::INVALID_ARGUMENT,
180+
return pbutil::Status(pbutil::StatusCode::kInvalidArgument,
182181
"Cannot find the type \"" + field->type_url() +
183182
"\" while parsing a field path.");
184183
}
185184
}
186185
}
187186
*field_path_out = std::move(field_path);
188-
return pbutil::Status::OK;
187+
return pbutil::Status();
189188
}
190189

191190
} // namespace transcoding

test/json_request_translator_test.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ namespace transcoding {
3434
namespace testing {
3535
namespace {
3636

37-
namespace pberr = google::protobuf::util::error;
38-
3937
// TranslationTestCase helps us build translation test cases and validate the
4038
// translation output.
4139
//
@@ -486,7 +484,7 @@ TEST_F(JsonRequestTranslatorTest, ErrorInvalidJson) {
486484
AddChunk(invalid);
487485
Finish();
488486
EXPECT_TRUE(Tester().ExpectNone());
489-
EXPECT_TRUE(Tester().ExpectStatusEq(pberr::INVALID_ARGUMENT));
487+
EXPECT_TRUE(Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument));
490488
}
491489
}
492490
}
@@ -735,7 +733,7 @@ TEST_F(JsonRequestTranslatorTest, StreamingErrorNotAnArray) {
735733
AddChunk(R"({"name" : "1"})");
736734
Finish();
737735
EXPECT_TRUE(Tester().ExpectNone());
738-
EXPECT_TRUE(Tester().ExpectStatusEq(pberr::INVALID_ARGUMENT));
736+
EXPECT_TRUE(Tester().ExpectStatusEq(google::protobuf::util::StatusCode::kInvalidArgument));
739737
}
740738

741739
} // namespace

test/message_reader_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ TEST_F(MessageReaderTest, IncompleteFrameHeader) {
384384

385385
EXPECT_EQ(nullptr, reader.NextMessage().get());
386386
EXPECT_FALSE(reader.Status().ok());
387-
EXPECT_EQ(reader.Status().error_message(),
387+
EXPECT_EQ(reader.Status().message(),
388388
"Incomplete gRPC frame header received");
389389
}
390390

@@ -397,7 +397,7 @@ TEST_F(MessageReaderTest, InvalidFrameFlag) {
397397

398398
EXPECT_EQ(nullptr, reader.NextMessage().get());
399399
EXPECT_FALSE(reader.Status().ok());
400-
EXPECT_EQ(reader.Status().error_message(), "Unsupported gRPC frame flag: 10");
400+
EXPECT_EQ(reader.Status().message(), "Unsupported gRPC frame flag: 10");
401401
}
402402

403403
TEST_F(MessageReaderTest, IncompleteFrame) {
@@ -409,7 +409,7 @@ TEST_F(MessageReaderTest, IncompleteFrame) {
409409

410410
EXPECT_EQ(nullptr, reader.NextMessage().get());
411411
EXPECT_FALSE(reader.Status().ok());
412-
EXPECT_EQ(reader.Status().error_message(),
412+
EXPECT_EQ(reader.Status().message(),
413413
"Incomplete gRPC frame expected size: 5 actual size: 1");
414414
}
415415

test/message_stream_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TestMessageStream : public MessageStream {
5353
}
5454
bool Finished() const { return messages_.empty() && finished_; }
5555
google::protobuf::util::Status Status() const {
56-
return google::protobuf::util::Status::OK;
56+
return google::protobuf::util::Status();
5757
}
5858

5959
private:

test/proto_stream_tester.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ProtoStreamTester::ProtoStreamTester(MessageStream& stream, bool delimiters)
3232

3333
bool ProtoStreamTester::ExpectNone() {
3434
// First check the status of the stream
35-
if (!ExpectStatusEq(google::protobuf::util::error::OK)) {
35+
if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) {
3636
return false;
3737
}
3838
std::string message;
@@ -46,7 +46,7 @@ bool ProtoStreamTester::ExpectNone() {
4646

4747
bool ProtoStreamTester::ExpectFinishedEq(bool expected) {
4848
// First check the status of the stream
49-
if (!ExpectStatusEq(google::protobuf::util::error::OK)) {
49+
if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) {
5050
return false;
5151
}
5252
if (expected != stream_.Finished()) {
@@ -78,7 +78,7 @@ unsigned DelimiterToSize(const unsigned char* delimiter) {
7878

7979
bool ProtoStreamTester::ValidateDelimiter(const std::string& message) {
8080
// First check the status of the stream
81-
if (!ExpectStatusEq(google::protobuf::util::error::OK)) {
81+
if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) {
8282
return false;
8383
}
8484
if (message.size() < kDelimiterSize) {
@@ -98,13 +98,13 @@ bool ProtoStreamTester::ValidateDelimiter(const std::string& message) {
9898
return true;
9999
}
100100

101-
bool ProtoStreamTester::ExpectStatusEq(int error_code) {
102-
if (error_code != stream_.Status().error_code()) {
101+
bool ProtoStreamTester::ExpectStatusEq(google::protobuf::util::StatusCode error_code) {
102+
if (error_code != stream_.Status().code()) {
103103
ADD_FAILURE()
104104
<< "ObjectTranslatorTest::ValidateStatus: Status doesn't match "
105105
"expected: "
106-
<< error_code << " actual: " << stream_.Status().error_code() << " - "
107-
<< stream_.Status().error_message() << std::endl;
106+
<< static_cast<int>(error_code) << " actual: " << static_cast<int>(stream_.Status().code()) << " - "
107+
<< stream_.Status().message() << std::endl;
108108
return false;
109109
}
110110
return true;

test/proto_stream_tester.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ProtoStreamTester {
4545
bool ExpectNextEq(const std::string& expected_proto_text);
4646
bool ExpectNone();
4747
bool ExpectFinishedEq(bool expected);
48-
bool ExpectStatusEq(int error_code);
48+
bool ExpectStatusEq(google::protobuf::util::StatusCode error_code);
4949

5050
private:
5151
// Validates the GRPC message delimiter at the beginning
@@ -61,7 +61,7 @@ class ProtoStreamTester {
6161
template <typename MessageType>
6262
bool ProtoStreamTester::ExpectNextEq(const std::string& expected_proto_text) {
6363
// First check the status of the stream
64-
if (!ExpectStatusEq(google::protobuf::util::error::OK)) {
64+
if (!ExpectStatusEq(google::protobuf::util::StatusCode::kOk)) {
6565
return false;
6666
}
6767
// Try to get a message
@@ -70,7 +70,7 @@ bool ProtoStreamTester::ExpectNextEq(const std::string& expected_proto_text) {
7070
ADD_FAILURE() << "ProtoStreamTester::ValidateNext: NextMessage() "
7171
"returned false\n";
7272
// Use ExpectStatusEq() to output the status if it's not OK.
73-
ExpectStatusEq(google::protobuf::util::error::OK);
73+
ExpectStatusEq(google::protobuf::util::StatusCode::kOk);
7474
return false;
7575
}
7676
// Validate the delimiter if it's expected

test/request_message_translator_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ TEST_F(RequestMessageTranslatorTest, UnexpectedScalarBody) {
447447
Input().RenderString("", "History");
448448

449449
EXPECT_TRUE(Tester().ExpectStatusEq(
450-
::google::protobuf::util::error::INVALID_ARGUMENT));
450+
::google::protobuf::util::StatusCode::kInvalidArgument));
451451
}
452452

453453
TEST_F(RequestMessageTranslatorTest, UnexpectedList) {
@@ -457,7 +457,7 @@ TEST_F(RequestMessageTranslatorTest, UnexpectedList) {
457457
Input().StartList("")->EndList();
458458

459459
EXPECT_TRUE(Tester().ExpectStatusEq(
460-
::google::protobuf::util::error::INVALID_ARGUMENT));
460+
::google::protobuf::util::StatusCode::kInvalidArgument));
461461
}
462462

463463
TEST_F(RequestMessageTranslatorTest, IgnoreUnkownFields) {

0 commit comments

Comments
 (0)