Skip to content

Commit 6f45dc7

Browse files
authored
[bugfix/MoreStability] Added more stability when a container errors (#29)
1 parent 584f0f9 commit 6f45dc7

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

JShellAPI/src/main/java/org/togetherjava/jshellapi/service/JShellService.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public Optional<List<String>> snippets(boolean includeStartupScript) throws Dock
167167
}
168168
return Optional.of(includeStartupScript ? snippets
169169
: snippets.subList(startupScriptSize, snippets.size()));
170-
} catch (IOException ex) {
170+
} catch (Exception ex) {
171171
LOGGER.warn("Unexpected error.", ex);
172172
close();
173173
throw new DockerException(ex);
@@ -234,30 +234,15 @@ private void updateLastTimeout() {
234234
private void checkContainerOK() throws DockerException {
235235
try {
236236
if (dockerService.isDead(containerName())) {
237-
try {
238-
close();
239-
} finally {
240-
throw new DockerException("Container of session " + id + " is dead");
241-
}
237+
throw new IOException("Container of session " + id + " is dead");
242238
}
243-
String OK = reader.readLine();
244-
if (OK == null) {
245-
try {
246-
close();
247-
} finally {
248-
throw new DockerException("Container of session " + id + " is dead");
249-
}
250-
}
251-
if (!OK.equals("OK")) {
252-
try {
253-
close();
254-
} finally {
255-
throw new DockerException(
256-
"Container of session " + id + " returned invalid info : " + OK);
257-
}
239+
String ok = reader.readLine();
240+
if (ok == null || !ok.equals("OK")) {
241+
throw new IOException(
242+
"Container of session " + id + " is dead because status was " + ok);
258243
}
259244
} catch (IOException ex) {
260-
LOGGER.warn("Unexpected error.", ex);
245+
close();
261246
throw new DockerException(ex);
262247
}
263248
}

0 commit comments

Comments
 (0)