|
34 | 34 | import java.io.IOException; |
35 | 35 | import java.io.InputStream; |
36 | 36 | import java.io.UncheckedIOException; |
37 | | -import java.nio.charset.StandardCharsets; |
38 | 37 | import java.nio.file.Path; |
39 | 38 | import java.nio.file.Paths; |
40 | 39 | import java.util.LinkedHashMap; |
41 | 40 | import java.util.Map; |
42 | 41 | import java.util.concurrent.TimeUnit; |
43 | 42 |
|
44 | 43 | import static org.openrewrite.internal.StringUtils.readFully; |
45 | | -import static org.openrewrite.internal.StringUtils.readFullyWithoutClosing; |
46 | 44 |
|
47 | 45 | /** |
48 | 46 | * A client for spawning and communicating with a subprocess that implements Rewrite RPC. |
@@ -97,16 +95,18 @@ public void run() { |
97 | 95 | public @Nullable RuntimeException getLivenessCheck() { |
98 | 96 | if (process != null && !process.isAlive()) { |
99 | 97 | int exitCode = process.exitValue(); |
100 | | - String message = "JavaScript RPC process shut down early with exit code " + exitCode; |
101 | | - |
102 | 98 | String errorOutput = "", stdOutput = ""; |
103 | | - try { |
104 | | - errorOutput = readFullyWithoutClosing(process.getErrorStream(), StandardCharsets.UTF_8); |
105 | | - stdOutput = readFullyWithoutClosing(process.getInputStream(), StandardCharsets.UTF_8); |
106 | | - } catch (UnsupportedOperationException e) { |
107 | | - message += "\nError retrieving output/error stream: " + e.getMessage(); |
| 99 | + |
| 100 | + // Read any remaining output from the process |
| 101 | + try (InputStream errorStream = process.getErrorStream(); |
| 102 | + InputStream inputStream = process.getInputStream()) { |
| 103 | + errorOutput = readFully(errorStream); |
| 104 | + stdOutput = readFully(inputStream); |
| 105 | + } catch (IOException | UnsupportedOperationException e) { |
| 106 | + // Ignore errors reading final output |
108 | 107 | } |
109 | 108 |
|
| 109 | + String message = "JavaScript RPC process shut down early with exit code " + exitCode; |
110 | 110 | if (!stdOutput.isEmpty()) { |
111 | 111 | message += "\nStandard output:\n " + stdOutput.replace("\n", "\n "); |
112 | 112 | } |
|
0 commit comments