2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 00:07:12 -07:00

Interrupt execution when exception triggers during command execution.

Minor refactoring.
This commit is contained in:
Geert Bevin 2024-06-26 08:02:02 -04:00
parent c912e4396e
commit b9ac76b5b5

View file

@ -250,54 +250,9 @@ public class BuildExecutor {
break;
}
} catch (Throwable e) {
exitStatus(1);
if (outputJson()) {
var t = TemplateFactory.JSON.get("bld.executor_error");
if (showStacktrace) {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
}
else {
boolean first_exception = true;
var e2 = e;
while (e2 != null) {
if (e2.getMessage() != null) {
t.setValueEncoded("error-message", e2.getMessage());
first_exception = false;
}
e2 = e2.getCause();
}
if (first_exception) {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
}
}
System.out.println(t.getContent());
}
else {
System.err.println();
if (showStacktrace) {
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
} else {
boolean first_exception = true;
var e2 = e;
while (e2 != null) {
if (e2.getMessage() != null) {
if (!first_exception) {
System.err.print("> ");
}
System.err.println(e2.getMessage());
first_exception = false;
}
e2 = e2.getCause();
}
if (first_exception) {
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
}
}
}
exitStatus(ExitStatusException.EXIT_FAILURE);
outputCommandExecutionException(e);
break;
}
}
@ -308,6 +263,55 @@ public class BuildExecutor {
return exitStatus_;
}
private void outputCommandExecutionException(Throwable e) {
if (outputJson()) {
var t = TemplateFactory.JSON.get("bld.executor_error");
if (showStacktrace) {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
}
else {
boolean first_exception = true;
var e2 = e;
while (e2 != null) {
if (e2.getMessage() != null) {
t.setValueEncoded("error-message", e2.getMessage());
first_exception = false;
}
e2 = e2.getCause();
}
if (first_exception) {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
}
}
System.out.println(t.getContent());
}
else {
System.err.println();
if (showStacktrace) {
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
} else {
boolean first_exception = true;
var e2 = e;
while (e2 != null) {
if (e2.getMessage() != null) {
if (!first_exception) {
System.err.print("> ");
}
System.err.println(e2.getMessage());
first_exception = false;
}
e2 = e2.getCause();
}
if (first_exception) {
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
}
}
}
}
/**
* Starts the execution of the build. This method will call
* System.exit() when done with the appropriate exit status.
@ -554,7 +558,7 @@ public class BuildExecutor {
System.err.println();
System.err.println("ERROR: " + message);
}
exitStatus(1);
exitStatus(ExitStatusException.EXIT_FAILURE);
return false;
}
return true;