/** * Sanitize the exception and ALL nested causes * <p> * This will MODIFY the stacktrace of the exception instance and all its causes irreversibly * * @param t a throwable * @return The root cause exception instances, with stack trace modified to filter out groovy runtime classes */ public static Throwable deepSanitize(Throwable t) { Throwable current = t; while (current.getCause() != null) { current = StackTraceUtils.sanitize(current.getCause()); } return StackTraceUtils.sanitize(t); } }
private void printStackTrace(String message, Throwable error) { if ((error instanceof BuildException) && error.getCause() != null) { error = error.getCause(); } if (!isVerbose() && !Boolean.getBoolean("micronaut.full.stacktrace")) { StackTraceUtils.deepSanitize(error); } StringWriter sw = new StringWriter(); PrintWriter ps = new PrintWriter(sw); message = message == null ? error.getMessage() : message; if (!isVerbose()) { message = message + STACKTRACE_FILTERED_MESSAGE; } ps.println(message); error.printStackTrace(ps); error(sw.toString()); }
/** * Get the root cause of an exception and sanitize it for display to the user * <p> * This will MODIFY the stacktrace of the root cause exception object and return it * * @param t a throwable * @return The root cause exception instance, with its stace trace modified to filter out groovy runtime classes */ public static Throwable sanitizeRootCause(Throwable t) { return StackTraceUtils.sanitize(StackTraceUtils.extractRootCause(t)); }
public static void printSanitizedStackTrace(Throwable t) { printSanitizedStackTrace(t, new PrintWriter(System.err)); }
/** * Remove all apparently groovy-internal trace entries from the exception instance * <p> * This modifies the original instance and returns it, it does not clone * * @param t the Throwable whose stack trace we want to sanitize * @return The original Throwable but with a sanitized stack trace */ public static Throwable sanitize(Throwable t) { // Note that this getBoolean access may well be synced... if (!SystemUtil.getBooleanSafe("groovy.full.stacktrace")) { StackTraceElement[] trace = t.getStackTrace(); List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement stackTraceElement : trace) { if (isApplicationClass(stackTraceElement.getClassName())) { newTrace.add(stackTraceElement); } } // We don't want to lose anything, so log it STACK_LOG.log(Level.WARNING, "Sanitizing stacktrace:", t); StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); } return t; }
public static void printSanitizedStackTrace(Throwable t) { printSanitizedStackTrace(t, new PrintWriter(System.err)); }
/** * <p>Remove all apparently groovy-internal trace entries from the exception instance</p> * <p>This modifies the original instance and returns it, it does not clone</p> * * @param t the Throwable whose stack trace we want to sanitize * @return The original Throwable but with a sanitized stack trace */ public static Throwable sanitize(Throwable t) { // Note that this getBoolean access may well be synced... if (!Boolean.getBoolean("groovy.full.stacktrace")) { StackTraceElement[] trace = t.getStackTrace(); List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement stackTraceElement : trace) { if (isApplicationClass(stackTraceElement.getClassName())) { newTrace.add(stackTraceElement); } } // We don't want to lose anything, so log it STACK_LOG.log(Level.WARNING, "Sanitizing stacktrace:", t); StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); } return t; }
public static void printSanitizedStackTrace(Throwable t, PrintWriter p) { t = StackTraceUtils.sanitize(t); StackTraceElement[] trace = t.getStackTrace(); for (StackTraceElement stackTraceElement : trace) { p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + ")"); } }
/** * <p>Get the root cause of an exception and sanitize it for display to the user</p> * <p>This will MODIFY the stacktrace of the root cause exception object and return it</p> * @param t * @return The root cause exception instance, with its stace trace modified to filter out groovy runtime classes */ public static Throwable sanitizeRootCause(Throwable t) { return StackTraceUtils.sanitize(StackTraceUtils.extractRootCause(t)); }
/** * Run the script. */ private boolean run() { try { if (processSockets) { processSockets(); } else if (processFiles) { processFiles(); } else { processOnce(); } return true; } catch (CompilationFailedException e) { System.err.println(e); return false; } catch (Throwable e) { if (e instanceof InvokerInvocationException) { InvokerInvocationException iie = (InvokerInvocationException) e; e = iie.getCause(); } System.err.println("Caught: " + e); if (!debug) { StackTraceUtils.deepSanitize(e); } e.printStackTrace(); return false; } }
public static void printSanitizedStackTrace(Throwable t) { printSanitizedStackTrace(t, new PrintWriter(System.err)); }
/** * <p>Remove all apparently groovy-internal trace entries from the exception instance</p> * <p>This modifies the original instance and returns it, it does not clone</p> * @param t * @return The exception passed in, after cleaning the stack trace */ public static Throwable sanitize(Throwable t) { // Note that this getBoolean access may well be synced... if (!Boolean.getBoolean("groovy.full.stacktrace")) { StackTraceElement[] trace = t.getStackTrace(); List newTrace = new ArrayList(); for (int i = 0; i < trace.length; i++) { StackTraceElement stackTraceElement = trace[i]; if (isApplicationClass(stackTraceElement.getClassName())) { newTrace.add( stackTraceElement); } } // We don't want to lose anything, so log it STACK_LOG.log(Level.WARNING, "Sanitizing stacktrace:", t); StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); } return t; }
public void error(int index, List<StringSection> sections, Throwable e) throws Throwable { int i = Math.max(0, index); StringSection precedingSection = sections.get(i); int traceLine = -1; for (StackTraceElement element : e.getStackTrace()) { if (element.getClassName().contains(TEMPLATE_SCRIPT_PREFIX)) { traceLine = element.getLineNumber(); break; } } if (traceLine != -1) { int actualLine = precedingSection.lastSourcePosition.row + traceLine - 1; String message = "Template execution error at line " + actualLine + ":\n" + getErrorContext(actualLine); TemplateExecutionException unsanitized = new TemplateExecutionException(actualLine, message, StackTraceUtils.sanitize(e)); throw StackTraceUtils.sanitize(unsanitized); } else { throw e; } }
/** * <p>Get the root cause of an exception and sanitize it for display to the user</p> * <p>This will MODIFY the stacktrace of the root cause exception object and return it</p> * * @param t a throwable * @return The root cause exception instance, with its stace trace modified to filter out groovy runtime classes */ public static Throwable sanitizeRootCause(Throwable t) { return StackTraceUtils.sanitize(StackTraceUtils.extractRootCause(t)); }
if (toFailureOnError) { session.revertReceivedTo(REL_FAILURE, StackTraceUtils.deepSanitize(t)); } else { session.rollback(true);
public static void printSanitizedStackTrace(Throwable t) { printSanitizedStackTrace(t, new PrintWriter(System.err)); }
/** * <p>Remove all apparently groovy-internal trace entries from the exception instance<p> * <p>This modifies the original instance and returns it, it does not clone</p> * @param t * @return The exception passed in, after cleaning the stack trace */ public static Throwable sanitize(Throwable t) { // Note that this getBoolean access may well be synced... if (!Boolean.getBoolean("groovy.full.stacktrace")) { StackTraceElement[] trace = t.getStackTrace(); List newTrace = new ArrayList(); for (int i = 0; i < trace.length; i++) { StackTraceElement stackTraceElement = trace[i]; if (isApplicationClass(stackTraceElement.getClassName())) { newTrace.add( stackTraceElement); } } // We don't want to lose anything, so log it STACK_LOG.log(Level.WARNING, "Sanitizing stacktrace:", t); StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); } return t; }
private TryResult handleError(String scriptName, Throwable e) { TryResult either; if (e instanceof InvocationTargetException) { e = ((InvocationTargetException) e).getTargetException(); } if (e instanceof InterruptedException || e instanceof InvocationTargetException || e instanceof ThreadDeath) { either = TryResult.createError(INTERUPTED_MSG); } else { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); StackTraceUtils.sanitize(e).printStackTrace(pw); String value = sw.toString(); value = printStacktrace(scriptName, value); either = TryResult.createError(value); } return either; }
/** * <p>Get the root cause of an exception and sanitize it for display to the user</p> * <p>This will MODIFY the stacktrace of the root cause exception object and return it</p> * @param t * @return The root cause exception instance, with its stace trace modified to filter out groovy runtime classes */ public static Throwable sanitizeRootCause(Throwable t) { return StackTraceUtils.sanitize(StackTraceUtils.extractRootCause(t)); }
public Throwable transform(Throwable exception) { return StackTraceUtils.deepSanitize(analyser.transform(exception)); } }