Truncate status messages before converting to gRPC.
authorBrennan Saeta <saeta@google.com>
Wed, 20 Dec 2017 22:47:04 +0000 (14:47 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 20 Dec 2017 22:50:27 +0000 (14:50 -0800)
PiperOrigin-RevId: 179736746

tensorflow/core/distributed_runtime/rpc/grpc_util.h

index ac0a33a2b9cbe2ba415a0f6cd7d94aee1fb142ac..bb854783472c4a5e1261e9e737f4b830e5cbf3e2 100644 (file)
@@ -23,6 +23,7 @@ limitations under the License.
 #include "grpc++/support/byte_buffer.h"
 #include "tensorflow/core/distributed_runtime/tensor_coding.h"
 #include "tensorflow/core/lib/core/status.h"
+#include "tensorflow/core/lib/strings/stringprintf.h"
 #include "tensorflow/core/platform/mutex.h"
 #include "tensorflow/core/platform/protobuf.h"
 
@@ -61,6 +62,13 @@ inline ::grpc::Status ToGrpcStatus(const ::tensorflow::Status& s) {
   if (s.ok()) {
     return ::grpc::Status::OK;
   } else {
+    if (s.error_message().size() > 3072 /* 3k bytes */) {
+      // TODO(b/62947679): Remove truncation once the gRPC issue is resolved.
+      string scratch =
+          strings::Printf("%.3072s ... [truncated]", s.error_message().c_str());
+      LOG(ERROR) << "Truncated error message: " << s;
+      return ::grpc::Status(static_cast<::grpc::StatusCode>(s.code()), scratch);
+    }
     return ::grpc::Status(static_cast<::grpc::StatusCode>(s.code()),
                           s.error_message());
   }