use of com.facebook.buck.util.BuckIsDyingException in project buck by facebook.
the class Main method runMainThenExit.
/* Define all error handling surrounding main command */
private void runMainThenExit(String[] args, Optional<NGContext> context, final long initTimestamp) {
installUncaughtExceptionHandler(context);
Path projectRoot = Paths.get(".");
int exitCode = FAIL_EXIT_CODE;
BuildId buildId = getBuildId(context);
// Only post an overflow event if Watchman indicates a fresh instance event
// after our initial query.
WatchmanWatcher.FreshInstanceAction watchmanFreshInstanceAction = daemon == null ? WatchmanWatcher.FreshInstanceAction.NONE : WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT;
// Get the client environment, either from this process or from the Nailgun context.
ImmutableMap<String, String> clientEnvironment = getClientEnvironment(context);
try {
CommandMode commandMode = CommandMode.RELEASE;
exitCode = runMainWithExitCode(buildId, projectRoot, context, clientEnvironment, commandMode, watchmanFreshInstanceAction, initTimestamp, args);
} catch (IOException e) {
if (e.getMessage().startsWith("No space left on device")) {
(new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)))).printBuildFailure(e.getMessage());
} else {
LOG.error(e);
}
} catch (HumanReadableException e) {
Console console = new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)));
console.printBuildFailure(e.getHumanReadableErrorMessage());
} catch (InterruptionFailedException e) {
// Command could not be interrupted.
if (context.isPresent()) {
// Exit process to halt command execution.
context.get().getNGServer().shutdown(true);
}
} catch (BuckIsDyingException e) {
LOG.warn(e, "Fallout because buck was already dying");
} catch (Throwable t) {
LOG.error(t, "Uncaught exception at top level");
} finally {
LOG.debug("Done.");
LogConfig.flushLogs();
// Exit explicitly so that non-daemon threads (of which we use many) don't
// keep the VM alive.
System.exit(exitCode);
}
}
Aggregations