|
34 | 34 | import java.io.IOException; |
35 | 35 | import java.io.InputStream; |
36 | 36 | import java.io.UncheckedIOException; |
| 37 | +import java.nio.charset.StandardCharsets; |
37 | 38 | import java.nio.file.Path; |
38 | 39 | import java.nio.file.Paths; |
39 | 40 | import java.util.LinkedHashMap; |
40 | 41 | import java.util.Map; |
41 | 42 | import java.util.concurrent.TimeUnit; |
42 | 43 |
|
43 | 44 | import static org.openrewrite.internal.StringUtils.readFully; |
| 45 | +import static org.openrewrite.internal.StringUtils.readFullyWithoutClosing; |
44 | 46 |
|
45 | 47 | /** |
46 | 48 | * A client for spawning and communicating with a subprocess that implements Rewrite RPC. |
@@ -95,18 +97,16 @@ public void run() { |
95 | 97 | public @Nullable RuntimeException getLivenessCheck() { |
96 | 98 | if (process != null && !process.isAlive()) { |
97 | 99 | int exitCode = process.exitValue(); |
98 | | - String errorOutput = "", stdOutput = ""; |
| 100 | + String message = "JavaScript RPC process shut down early with exit code " + exitCode; |
99 | 101 |
|
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 |
| 102 | + 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(); |
107 | 108 | } |
108 | 109 |
|
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