From 74c106eff3d1a43ee9e4823c9dfdd28540591ec1 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Wed, 15 Nov 2017 18:43:00 -0800 Subject: Add error string to C++ --- include/grpc++/impl/codegen/call.h | 6 ++++-- include/grpc++/impl/codegen/status.h | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'include/grpc++') diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index af2c2b510c..6a2ac8b70c 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -574,7 +574,7 @@ class CallOpClientRecvStatus { op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); op->data.recv_status_on_client.status = &status_code_; op->data.recv_status_on_client.status_details = &error_message_; - op->data.recv_status_on_client.error_string = nullptr; + op->data.recv_status_on_client.error_string = &error_string_; op->flags = 0; op->reserved = NULL; } @@ -591,14 +591,16 @@ class CallOpClientRecvStatus { *recv_status_ = Status(static_cast(status_code_), grpc::string(GRPC_SLICE_START_PTR(error_message_), GRPC_SLICE_END_PTR(error_message_)), - binary_error_details); + binary_error_details, grpc::string(error_string_)); g_core_codegen_interface->grpc_slice_unref(error_message_); + g_core_codegen_interface->gpr_free((void*)error_string_); recv_status_ = nullptr; } private: MetadataMap* metadata_map_; Status* recv_status_; + const char* error_string_; grpc_status_code status_code_; grpc_slice error_message_; }; diff --git a/include/grpc++/impl/codegen/status.h b/include/grpc++/impl/codegen/status.h index 6f013cf0ca..cdaf5e1706 100644 --- a/include/grpc++/impl/codegen/status.h +++ b/include/grpc++/impl/codegen/status.h @@ -46,6 +46,16 @@ class Status { error_message_(error_message), binary_error_details_(error_details) {} + /// Construct an instance with \a code, \a error_message and + /// \a error_details. It is an error to construct an OK status with non-empty + /// \a error_message and/or \a error_details. + Status(StatusCode code, const grpc::string& error_message, + const grpc::string& error_details, const grpc::string& error_string) + : code_(code), + error_message_(error_message), + binary_error_details_(error_details), + error_string_(error_string) {} + // Pre-defined special status objects. /// An OK pre-defined instance. static const Status& OK; @@ -59,6 +69,8 @@ class Status { /// Return the (binary) error details. // Usually it contains a serialized google.rpc.Status proto. grpc::string error_details() const { return binary_error_details_; } + /// Return the full fidelity error string, which includes all child errors. + grpc::string error_string() const { return error_string_; } /// Is the status OK? bool ok() const { return code_ == StatusCode::OK; } @@ -72,6 +84,7 @@ class Status { StatusCode code_; grpc::string error_message_; grpc::string binary_error_details_; + grpc::string error_string_; }; } // namespace grpc -- cgit v1.2.3