/** * Gets exception string. * * @param e the e * @return the exception string */ @Nonnull public static CharSequence getExceptionString(Throwable e) { if (e instanceof RuntimeException && e.getCause() != null && e.getCause() != e) return getExceptionString(e.getCause()); if (e.getCause() != null && e.getCause() != e) return e.getClass().getSimpleName() + " / " + getExceptionString(e.getCause()); return e.getClass().getSimpleName(); }
/** * Gets exception string. * * @param e the e * @return the exception string */ @Nonnull public static CharSequence getExceptionString(Throwable e) { if (e instanceof RuntimeException && e.getCause() != null && e.getCause() != e) return getExceptionString(e.getCause()); if (e.getCause() != null && e.getCause() != e) return e.getClass().getSimpleName() + " / " + getExceptionString(e.getCause()); return e.getClass().getSimpleName(); }
/** * Wrap frontmatter consumer. * * @param fn the fn * @return the consumer */ public static Consumer<NotebookOutput> wrapFrontmatter(@Nonnull final Consumer<NotebookOutput> fn) { return log -> { @Nonnull TimedResult<Void> time = TimedResult.time(() -> { try { fn.accept(log); log.setFrontMatterProperty("result", "OK"); } catch (Throwable e) { log.setFrontMatterProperty("result", getExceptionString(e).toString().replaceAll("\n", "<br/>").trim()); throw (RuntimeException) (e instanceof RuntimeException ? e : new RuntimeException(e)); } }); log.setFrontMatterProperty("execution_time", String.format("%.6f", time.timeNanos / 1e9)); }; }
/** * Wrap frontmatter consumer. * * @param fn the fn * @return the consumer */ public static Consumer<NotebookOutput> wrapFrontmatter(@Nonnull final Consumer<NotebookOutput> fn) { return log -> { @Nonnull TimedResult<Void> time = TimedResult.time(() -> { try { fn.accept(log); log.setFrontMatterProperty("result", "OK"); } catch (Throwable e) { log.setFrontMatterProperty("result", getExceptionString(e).toString().replaceAll("\n", "<br/>").trim()); throw (RuntimeException) (e instanceof RuntimeException ? e : new RuntimeException(e)); } }); log.setFrontMatterProperty("execution_time", String.format("%.6f", time.timeNanos / 1e9)); }; }