mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 08:17:11 -07:00
Interrupt execution when exception triggers during command execution.
Minor refactoring.
This commit is contained in:
parent
c912e4396e
commit
b9ac76b5b5
1 changed files with 53 additions and 49 deletions
|
@ -250,54 +250,9 @@ public class BuildExecutor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
exitStatus(1);
|
exitStatus(ExitStatusException.EXIT_FAILURE);
|
||||||
|
outputCommandExecutionException(e);
|
||||||
if (outputJson()) {
|
break;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,6 +263,55 @@ public class BuildExecutor {
|
||||||
return exitStatus_;
|
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
|
* Starts the execution of the build. This method will call
|
||||||
* System.exit() when done with the appropriate exit status.
|
* System.exit() when done with the appropriate exit status.
|
||||||
|
@ -554,7 +558,7 @@ public class BuildExecutor {
|
||||||
System.err.println();
|
System.err.println();
|
||||||
System.err.println("ERROR: " + message);
|
System.err.println("ERROR: " + message);
|
||||||
}
|
}
|
||||||
exitStatus(1);
|
exitStatus(ExitStatusException.EXIT_FAILURE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue