You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ch...@apache.org on 2019/01/29 21:15:15 UTC

[mesos] 05/06: Improved error printing for gRPC statuses.

This is an automated email from the ASF dual-hosted git repository.

chhsiao pushed a commit to branch 1.7.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 80c72a1b895ea1fbca6a977d0599033d27d80c75
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Tue Jan 22 22:55:14 2019 -0800

    Improved error printing for gRPC statuses.
    
    This patch prepends the error message of a `process::grpc::StatusError`
    with its status code.
    
    Review: https://reviews.apache.org/r/69813
---
 3rdparty/libprocess/include/process/grpc.hpp | 14 +++++++-
 3rdparty/libprocess/src/grpc.cpp             | 53 ++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/3rdparty/libprocess/include/process/grpc.hpp b/3rdparty/libprocess/include/process/grpc.hpp
index 28c9cad..f5236c4 100644
--- a/3rdparty/libprocess/include/process/grpc.hpp
+++ b/3rdparty/libprocess/include/process/grpc.hpp
@@ -15,6 +15,7 @@
 
 #include <chrono>
 #include <memory>
+#include <ostream>
 #include <string>
 #include <thread>
 #include <type_traits>
@@ -34,6 +35,7 @@
 #include <stout/error.hpp>
 #include <stout/lambda.hpp>
 #include <stout/nothing.hpp>
+#include <stout/stringify.hpp>
 #include <stout/try.hpp>
 
 
@@ -47,6 +49,13 @@
 #define GRPC_CLIENT_METHOD(service, rpc) \
   (&service::Stub::PrepareAsync##rpc)
 
+namespace grpc {
+
+std::ostream& operator<<(std::ostream& stream, StatusCode statusCode);
+
+} // namespace grpc {
+
+
 namespace process {
 namespace grpc {
 
@@ -58,7 +67,10 @@ class StatusError : public Error
 {
 public:
   StatusError(::grpc::Status _status)
-    : Error(_status.error_message()), status(std::move(_status))
+    : Error(stringify(_status.error_code()) +
+            (_status.error_message().empty()
+               ? "" : ": " + _status.error_message())),
+      status(std::move(_status))
   {
     CHECK(!status.ok());
   }
diff --git a/3rdparty/libprocess/src/grpc.cpp b/3rdparty/libprocess/src/grpc.cpp
index 4e4f989..14017c5 100644
--- a/3rdparty/libprocess/src/grpc.cpp
+++ b/3rdparty/libprocess/src/grpc.cpp
@@ -16,6 +16,59 @@
 #include <process/id.hpp>
 #include <process/process.hpp>
 
+#include <stout/unreachable.hpp>
+
+using std::ostream;
+
+namespace grpc {
+
+ostream& operator<<(ostream& stream, StatusCode statusCode)
+{
+  switch (statusCode) {
+    case OK:
+      return stream << "OK";
+    case CANCELLED:
+      return stream << "CANCELLED";
+    case UNKNOWN:
+      return stream << "UNKNOWN";
+    case INVALID_ARGUMENT:
+      return stream << "INVALID_ARGUMENT";
+    case DEADLINE_EXCEEDED:
+      return stream << "DEADLINE_EXCEEDED";
+    case NOT_FOUND:
+      return stream << "NOT_FOUND";
+    case ALREADY_EXISTS:
+      return stream << "ALREADY_EXISTS";
+    case PERMISSION_DENIED:
+      return stream << "PERMISSION_DENIED";
+    case UNAUTHENTICATED:
+      return stream << "UNAUTHENTICATED";
+    case RESOURCE_EXHAUSTED:
+      return stream << "RESOURCE_EXHAUSTED";
+    case FAILED_PRECONDITION:
+      return stream << "FAILED_PRECONDITION";
+    case ABORTED:
+      return stream << "ABORTED";
+    case OUT_OF_RANGE:
+      return stream << "OUT_OF_RANGE";
+    case UNIMPLEMENTED:
+      return stream << "UNIMPLEMENTED";
+    case INTERNAL:
+      return stream << "INTERNAL";
+    case UNAVAILABLE:
+      return stream << "UNAVAILABLE";
+    case DATA_LOSS:
+      return stream << "DATA_LOSS";
+    case DO_NOT_USE:
+      return stream << "DO_NOT_USE";
+  }
+
+  UNREACHABLE();
+}
+
+} // namespace grpc {
+
+
 namespace process {
 namespace grpc {
 namespace client {