From ef4df091974f3455ad468c57bb51af4f687c3717 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 5 Nov 2014 19:30:37 +0000 Subject: [PATCH] * improved error output --- source/net/filebot/cli/ArgumentProcessor.java | 12 +++++++----- source/net/filebot/cli/ScriptShellBaseClass.java | 2 +- source/net/filebot/util/ExceptionUtilities.java | 10 ++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/cli/ArgumentProcessor.java b/source/net/filebot/cli/ArgumentProcessor.java index a3210e04..c535f8fa 100644 --- a/source/net/filebot/cli/ArgumentProcessor.java +++ b/source/net/filebot/cli/ArgumentProcessor.java @@ -117,12 +117,14 @@ public class ArgumentProcessor { // script finished successfully CLILogger.finest("Done ヾ(@⌒ー⌒@)ノ"); return 0; - } catch (CmdlineException e) { - CLILogger.log(Level.WARNING, e.getMessage()); - } catch (ScriptDeath e) { - CLILogger.log(Level.WARNING, e.getMessage(), e.getCause()); } catch (Throwable e) { - CLILogger.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), getRootCause(e)); + if (findCause(e, CmdlineException.class) != null) { + CLILogger.log(Level.WARNING, findCause(e, CmdlineException.class).getMessage()); + } else if (findCause(e, ScriptDeath.class) != null) { + CLILogger.log(Level.WARNING, findCause(e, ScriptDeath.class).getMessage()); + } else { + CLILogger.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), getRootCause(e)); + } } // script failed diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 4c0071ca..36c7f458 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -147,7 +147,7 @@ public abstract class ScriptShellBaseClass extends Script { if (cause instanceof Throwable) { throw new ScriptDeath((Throwable) cause); } - throw new ScriptDeath(cause.toString()); + throw new ScriptDeath(String.valueOf(cause)); } // define global variable: _args diff --git a/source/net/filebot/util/ExceptionUtilities.java b/source/net/filebot/util/ExceptionUtilities.java index d8ac8e41..e81befac 100644 --- a/source/net/filebot/util/ExceptionUtilities.java +++ b/source/net/filebot/util/ExceptionUtilities.java @@ -1,10 +1,20 @@ package net.filebot.util; +import static java.util.Arrays.*; + import java.io.PrintWriter; import java.io.StringWriter; public final class ExceptionUtilities { + public static T shiftStackTrace(T t, int offset) { + StackTraceElement[] stackTrace = t.getStackTrace(); + if (offset < stackTrace.length) { + t.setStackTrace(copyOfRange(stackTrace, offset, stackTrace.length)); + } + return t; + } + public static Throwable getRootCause(Throwable t) { while (t.getCause() != null) { t = t.getCause();