Skip to content

Commit

Permalink
Improve exception print (wgzhao#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao authored May 24, 2024
1 parent 8e452e4 commit 11e1ccf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/src/main/java/com/wgzhao/addax/core/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.wgzhao.addax.core.job.JobContainer;
import com.wgzhao.addax.core.util.ConfigParser;
import com.wgzhao.addax.core.util.ConfigurationValidate;
import com.wgzhao.addax.core.util.ExceptionTracker;
import com.wgzhao.addax.core.util.container.LoadUtil;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -134,12 +135,10 @@ public static void main(String[] args) {
LOG.error("need a job file");
System.exit(1);
}

try {
Engine.entry(args);
} catch (Throwable e) {
e.printStackTrace();
LOG.error(e.toString());
LOG.error(ExceptionTracker.trace(e));
System.exit(2);
}
System.exit(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wgzhao.addax.core.util;

public class ExceptionTracker
{
public static final int STRING_BUFFER = 4096;

public static String trace(Throwable e) {
StringBuilder sb = new StringBuilder(STRING_BUFFER);
sb.append(e.toString()).append("\n");
StackTraceElement[] stackTrace = e.getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
sb.append("\t").append(stackTraceElement).append("\n");
}
return sb.toString();
}
}

0 comments on commit 11e1ccf

Please sign in to comment.