Java Code Examples for org.codehaus.groovy.runtime.StackTraceUtils#deepSanitize()

The following examples show how to use org.codehaus.groovy.runtime.StackTraceUtils#deepSanitize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
  try {
    Script script = getGroovyScript(contextInterpreter.getParagraphId(), cmd);
    Job runningJob = getRunningJob(contextInterpreter.getParagraphId());
    runningJob.info()
        .put("CURRENT_THREAD", Thread.currentThread()); //to be able to terminate thread
    Map<String, Object> bindings = script.getBinding().getVariables();
    bindings.clear();
    StringWriter out = new StringWriter((int) (cmd.length() * 1.75));
    //put shared bindings evaluated in this interpreter
    bindings.putAll(sharedBindings);
    //put predefined bindings
    bindings.put("g", new GObject(log, out, this.getProperties(), contextInterpreter, bindings));
    bindings.put("out", new PrintWriter(out, true));

    script.run();
    //let's get shared variables defined in current script and store them in shared map
    for (Map.Entry<String, Object> e : bindings.entrySet()) {
      if (!predefinedBindings.contains(e.getKey())) {
        if (log.isTraceEnabled()) {
          log.trace("groovy script variable " + e);  //let's see what we have...
        }
        sharedBindings.put(e.getKey(), e.getValue());
      }
    }

    bindings.clear();
    InterpreterResult result = new InterpreterResult(Code.SUCCESS, out.toString());
    return result;
  } catch (Throwable t) {
    t = StackTraceUtils.deepSanitize(t);
    String msg = t.toString() + "\n at " + t.getStackTrace()[0];
    log.error("Failed to run script: " + t + "\n" + cmd + "\n", t);
    return new InterpreterResult(Code.ERROR, msg);
  }
}
 
Example 2
Source File: StackTraceSanitizingExceptionAnalyser.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Throwable transform(Throwable exception) {
    return StackTraceUtils.deepSanitize(analyser.transform(exception));
}
 
Example 3
Source File: BuildExceptionReporter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void writeFailureDetails(StyledTextOutput output, FailureDetails details) {
    if (details.location.getHasContent()) {
        output.println();
        output.println("* Where:");
        details.location.writeTo(output);
        output.println();
    }

    if (details.details.getHasContent()) {
        output.println();
        output.println("* What went wrong:");
        details.details.writeTo(output);
        output.println();
    }

    if (details.resolution.getHasContent()) {
        output.println();
        output.println("* Try:");
        details.resolution.writeTo(output);
        output.println();
    }

    Throwable exception = null;
    switch (details.exceptionStyle) {
        case NONE:
            break;
        case SANITIZED:
            exception = StackTraceUtils.deepSanitize(details.failure);
            break;
        case FULL:
            exception = details.failure;
            break;
    }

    if (exception != null) {
        output.println();
        output.println("* Exception is:");
        output.exception(exception);
        output.println();
    }
}
 
Example 4
Source File: StackTraceSanitizingExceptionAnalyser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Throwable transform(Throwable exception) {
    return StackTraceUtils.deepSanitize(analyser.transform(exception));
}
 
Example 5
Source File: BuildExceptionReporter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void writeFailureDetails(StyledTextOutput output, FailureDetails details) {
    if (details.location.getHasContent()) {
        output.println();
        output.println("* Where:");
        details.location.writeTo(output);
        output.println();
    }

    if (details.details.getHasContent()) {
        output.println();
        output.println("* What went wrong:");
        details.details.writeTo(output);
        output.println();
    }

    if (details.resolution.getHasContent()) {
        output.println();
        output.println("* Try:");
        details.resolution.writeTo(output);
        output.println();
    }

    Throwable exception = null;
    switch (details.exceptionStyle) {
        case NONE:
            break;
        case SANITIZED:
            exception = StackTraceUtils.deepSanitize(details.failure);
            break;
        case FULL:
            exception = details.failure;
            break;
    }

    if (exception != null) {
        output.println();
        output.println("* Exception is:");
        output.exception(exception);
        output.println();
    }
}