Skip to content

Commit

Permalink
Update test code to log error message
Browse files Browse the repository at this point in the history
  • Loading branch information
zoewangg committed Dec 10, 2024
1 parent fd0edca commit 12df7e8
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
Expand Down Expand Up @@ -147,7 +148,14 @@ public static Result run(Path dir, String... args) {
IoUtils.copy(process.getInputStream(), System.out);
result.result = process.waitFor();
if (!result.wasSuccessful()) {
throw new RuntimeException("Command (" + Arrays.toString(args) + ") failed: " + result.output);
String errorMsg = null;
try (InputStream errorStream = process.getErrorStream()) {
if (errorStream != null) {
errorMsg = IoUtils.toUtf8String(errorStream);
}
}
throw new RuntimeException(String.format("Command (%s) failed of error code: %d, error message: %s",
Arrays.toString(args), result.result, errorMsg));
}
} finally {
process.destroy();
Expand Down

0 comments on commit 12df7e8

Please sign in to comment.