SnapDataException is swallowing my stack trace string

I’m having an issue right now with how the SnapDataException handles a full stacktrace event.

Essentially this happens in developing snaps when we don’t have all the right jar files. The workaround is easy because I can set ERROR on output and check it, but it’s irritating because I’d like to have the Snap return an error and then show me the whole stack trace to troubleshoot.

    } catch (Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        content.put("ERROR", sw.toString());
        TB - 4/15/21
        SnapDataException is really irritating and will delete the error message.
        You need to trap error in the pipeline or uncomment/comment this.
        throw new SnapDataException(document,
                String.format("Unexpected error: ", e.toString() + "/" + sw.toString()));*/

Your form swallows the caught exception, but you manually capture the stack trace. Alternatively, you could preserve the underlying exception by passing it to the SnapDataException using this constructor:

SnapDataException(Document document, Throwable cause, String message);

Often times, the snap exception is written to the error view.


There is a write() which accepts a document too

errorViews.write(snapDataException, document)

The write will extract the underlying exception and stringify it, something like:


Throwables.getStackTraceAsString( snapDataException.getCause() );

Throwables is a Guava class. Your vanilla Java approach works too – a bit more work. Anyway, the stack trace of the root exception should display in the error view.

1 Like