Skip to content

Commit 0bc0aad

Browse files
Improve error handling to avoid generic catchall
1 parent f58762b commit 0bc0aad

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecProc.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ public int join() throws IOException, InterruptedException {
9494
LOGGER.log(Level.FINEST, "Command is finished ({0})", finished);
9595

9696
CompletableFuture<Integer> exitCodeFuture = watch.exitCode();
97+
98+
if (exitCodeFuture == null) {
99+
LOGGER.log(Level.FINEST, "exitCodeFuture is null.");
100+
printStream.print("exitCodeFuture is null.");
101+
return -1;
102+
}
103+
97104
Integer exitCode = exitCodeFuture.get();
98105

99106
if (exitCode == null) {
@@ -103,12 +110,14 @@ public int join() throws IOException, InterruptedException {
103110
}
104111
return exitCode;
105112
} catch (ExecutionException e) {
106-
LOGGER.log(Level.FINEST, "ExecutionException occurred while waiting for exit code", e.getCause());
107-
printStream.printf("ExecutionException occurred while waiting for exit code: %s%n", e.getCause());
108-
return -1;
109-
} catch (Exception e) {
110-
LOGGER.log(Level.FINEST, "Exception occurred while waiting for exit code", e);
111-
printStream.printf("Exception occurred while waiting for exit code: %s%n", e);
113+
Throwable cause = e.getCause();
114+
if (cause != null) {
115+
LOGGER.log(Level.FINEST, "ExecutionException occurred while waiting for exit code", cause);
116+
printStream.printf("ExecutionException occurred while waiting for exit code: %s%n", cause);
117+
} else {
118+
LOGGER.log(Level.FINEST, "ExecutionException occurred while waiting for exit code", e);
119+
printStream.printf("ExecutionException occurred while waiting for exit code: %s%n", e);
120+
}
112121
return -1;
113122
} finally {
114123
close();

0 commit comments

Comments
 (0)