From 7c0b5f02694ccd76cf42e7f7098e003db0d1071b Mon Sep 17 00:00:00 2001 From: Justen Walker Date: Sat, 24 Apr 2021 04:14:16 -0400 Subject: [PATCH] feat: improve grpc exception descriptions add stacktrace and exception class to GRPC exception --- .../goodwill/service/GrpcDockerService.java | 2 +- .../concord/goodwill/service/GrpcUtils.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/tech/justen/concord/goodwill/service/GrpcDockerService.java b/src/main/java/tech/justen/concord/goodwill/service/GrpcDockerService.java index 6ae4e3b..223c930 100644 --- a/src/main/java/tech/justen/concord/goodwill/service/GrpcDockerService.java +++ b/src/main/java/tech/justen/concord/goodwill/service/GrpcDockerService.java @@ -34,7 +34,7 @@ public void runContainer(DockerContainerSpec request, StreamObserver value) { } public static StatusRuntimeException toStatusException(Exception ex) { - return Status.INTERNAL.withDescription(ex.getMessage()).withCause(ex).asRuntimeException(); + return Status.INTERNAL.withDescription(exceptionDescription(ex)).withCause(ex).asRuntimeException(); } public static StatusRuntimeException toStatusException(ApiException ex, String desc) { @@ -210,4 +213,16 @@ public static StatusRuntimeException toStatusException(ApiException ex, String d } return status.withDescription(ex.getMessage()).withCause(ex).asRuntimeException(); } + + private static String exceptionDescription(Throwable ex) { + StringWriter sw = new StringWriter(); + sw.append(ex.getClass().getName()); + if (ex.getMessage() != null) { + sw.append(": "); + sw.append(ex.getMessage()); + sw.append('\n'); + } + ex.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } }