in src/main/java/com/spotify/fmt/ForkingExecutor.java [207:254]
T waitFor() {
if (process == null) {
throw new IllegalStateException();
}
log.debug("Waiting for subprocess exit");
final int exitValue;
try {
exitValue = process.waitFor();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} finally {
process.destroyForcibly();
}
log.debug("Subprocess exited: " + exitValue);
if (exitValue != 0) {
throw new RuntimeException("Subprocess failed: " + process.exitValue());
}
if (Files.exists(errorFile)) {
// Failed
log.debug("Subprocess exited with error file");
final Throwable error;
try {
error = Serialization.deserialize(errorFile);
} catch (SerializationException e) {
throw new RuntimeException("Failed to deserialize error", e);
}
if (error instanceof Error) {
throw (Error) error;
} else if (error instanceof RuntimeException) {
throw (RuntimeException) error;
} else {
throw new RuntimeException(error);
}
} else {
// Success
log.debug("Subprocess exited with result file");
final T result;
try {
result = Serialization.deserialize(resultFile);
} catch (SerializationException e) {
throw new RuntimeException("Failed to deserialize result", e);
}
return result;
}
}