Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception print #1038

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}