Skip to content

Commit 43de81e

Browse files
committed
[bugfix/MoreStability] Added more stability when a container errors
1 parent 584f0f9 commit 43de81e

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ public Optional<List<String>> snippets(boolean includeStartupScript) throws Dock
165165
while (!(snippet = reader.readLine()).isEmpty()) {
166166
snippets.add(cleanCode(snippet));
167167
}
168-
return Optional.of(includeStartupScript ? snippets
169-
: snippets.subList(startupScriptSize, snippets.size()));
170-
} catch (IOException ex) {
168+
return Optional.of(
169+
includeStartupScript
170+
? snippets
171+
: snippets.subList(startupScriptSize, snippets.size()));
172+
} catch (Exception ex) {
171173
LOGGER.warn("Unexpected error.", ex);
172174
close();
173175
throw new DockerException(ex);
@@ -234,30 +236,14 @@ private void updateLastTimeout() {
234236
private void checkContainerOK() throws DockerException {
235237
try {
236238
if (dockerService.isDead(containerName())) {
237-
try {
238-
close();
239-
} finally {
240-
throw new DockerException("Container of session " + id + " is dead");
241-
}
239+
throw new IOException("Container of session " + id + " is dead");
242240
}
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-
}
241+
String ok = reader.readLine();
242+
if (ok == null || !ok.equals("OK")) {
243+
throw new IOException("Container of session " + id + " is dead because status was " + ok);
258244
}
259245
} catch (IOException ex) {
260-
LOGGER.warn("Unexpected error.", ex);
246+
close();
261247
throw new DockerException(ex);
262248
}
263249
}

0 commit comments

Comments
 (0)