Skip to content

Commit

Permalink
Interrupt execution when exception triggers during command execution.
Browse files Browse the repository at this point in the history
Minor refactoring.
  • Loading branch information
gbevin committed Jun 26, 2024
1 parent c912e43 commit b9ac76b
Showing 1 changed file with 51 additions and 47 deletions.
98 changes: 51 additions & 47 deletions src/main/java/rife/bld/BuildExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,62 +250,66 @@ public int execute(String[] arguments) {
break;
}
} catch (Throwable e) {
exitStatus(1);
exitStatus(ExitStatusException.EXIT_FAILURE);
outputCommandExecutionException(e);
break;
}
}

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 (outputJson() && exitStatus_ == ExitStatusException.EXIT_SUCCESS) {
System.out.println(json_template.getContent());
}

if (first_exception) {
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
}
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;
}
System.out.println(t.getContent());
e2 = e2.getCause();
}
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));
}
}
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 (outputJson() && exitStatus_ == ExitStatusException.EXIT_SUCCESS) {
System.out.println(json_template.getContent());
if (first_exception) {
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
}
}
}

return exitStatus_;
}

/**
Expand Down Expand Up @@ -554,7 +558,7 @@ private boolean executeCommand(Template jsonTemplate, String command)
System.err.println();
System.err.println("ERROR: " + message);
}
exitStatus(1);
exitStatus(ExitStatusException.EXIT_FAILURE);
return false;
}
return true;
Expand Down

0 comments on commit b9ac76b

Please sign in to comment.