Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Handle unexpected errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mcartoixa committed Feb 24, 2021
1 parent 4d873dd commit 2e6da34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main/com/mcartoixa/ant/sfdx/ErrorOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.mcartoixa.ant.sfdx;

import java.io.IOException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.LineOrientedOutputStream;

Expand All @@ -32,16 +33,25 @@ public class ErrorOutputStream extends LineOrientedOutputStream {
public ErrorOutputStream(final ISfdxOutputHandler handler) {
super();
this.handler = handler;
this.errorMessage = "";
}

@Override
protected void processLine(final String string) {
if (string != null && !string.isEmpty()) {
// Proper messages will be generated from the JSON response (if there is one!)
handler.log(string, Project.MSG_VERBOSE);
this.errorMessage = this.errorMessage.concat(string + "\n");
}
}

private final transient ISfdxOutputHandler handler;
@Override
public void close() throws IOException {
if (!this.errorMessage.isEmpty()) {
handler.setErrorMessage(this.errorMessage);
}
super.close();
}

private final transient ISfdxOutputHandler handler;
private transient String errorMessage;
}
3 changes: 2 additions & 1 deletion src/main/com/mcartoixa/ant/sfdx/ISfdxOutputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
public interface ISfdxOutputHandler {

void log(String message, int level);


void setErrorMessage(String message);
}
7 changes: 7 additions & 0 deletions src/main/com/mcartoixa/ant/sfdx/SfdxTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public void parse(final JSONObject json) {
}
}

@Override
public void setErrorMessage(final String message) {
if (SfdxTask.this.getFailOnError() && !SfdxTask.this.hasErrorMessage()) {
SfdxTask.this.setErrorMessage(message.trim());
}
}

@SuppressWarnings({"PMD.DataflowAnomalyAnalysis", "PMD.NPathComplexity"})
protected void doParse(final JSONObject json) {
final int status = json.optInt("status");
Expand Down

0 comments on commit 2e6da34

Please sign in to comment.