Skip to content

Commit b6a08ab

Browse files
authored
Improve logging when git diff fails (#1490)
Improve logging when `git diff` fails
1 parent 9d6b8f4 commit b6a08ab

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle

gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ private static String gitCommand(Path dir, String... args) throws IOException, I
134134
new ProcessBuilder().command(args).directory(dir.toFile()).start();
135135

136136
Preconditions.checkState(process.waitFor(30, TimeUnit.SECONDS), "git diff took too long to terminate");
137-
Preconditions.checkState(process.exitValue() == 0, "Expected return code of 0");
138-
137+
if (process.exitValue() != 0) {
138+
throw new RuntimeException("Expected return code of 0 but got " + process.exitValue()
139+
+ "\n stdout: " + new String(process.getInputStream().readAllBytes())
140+
+ "\n stderr: " + new String(process.getErrorStream().readAllBytes()));
141+
}
139142
ByteArrayOutputStream baos = new ByteArrayOutputStream();
140143
process.getInputStream().transferTo(baos);
141144
return new String(baos.toByteArray(), UTF_8).trim();

0 commit comments

Comments
 (0)