arachne.error

Tools for creating, throwing, catching and printing useful error messages in
a standardized way. See ADR-13.

*default-explain-opts*

dynamic

Default options for how values are displayed. Can be reset or dynamically rebound to change how errors are explained. (see doc for `explain` function)

*print-exception*

dynamic

exception printer used for logging (among other things). Rebind to override how Arachne prints exceptions.

arachne-ex

(arachne-ex key ex-data)(arachne-ex key ex-data cause)
Construct an ArachneException for use by `log-error` or `error`

assert

(assert spec data error-type ex-data)
Assert the given data against the given spec, throwing the specified error
and ex-data if validation fails.

assert-args

(assert-args fn-sym & args)
Given a fully qualified symbol naming a function and some number of
arguments, assert that the arguments are valid according to the spec
attached to the function. If not, throw an ArachneException with an
explanation.

bullet-list

(bullet-list items)
Format a sequence of items into a string containing a series of bullet points.

deferror

(deferror type & kwargs)
Add an error message to the error message registry

error

macro

(error & [msg ex-data cause])
Throw an ex-info with the given error message lookup key, optional cause, and
ex-data map. The message string may contain :keywords which will be replaced
by their corresponding values from the ex-data, if present.

This is implemented as a macro so as to not show up in stack traces.

error-registry

global registry of Arachne error types and associated data

error-type?

(error-type? exception type)
Helper function to determine if an error is of the given type. Type may be a
class or a value of :arachne.error/type

explain

(explain)(explain e & {:as opts})
Print a pretty, formatted explanation of the most recent error to stdout.

Options are:

:color - use rudimentary ANSI color in the output (default true).
:suggestions - Show any suggestions in the error (default true).
:ex-data-summary - Show a table of the keys available in the exception's ex-data (default true)
:cause - Show the exception's cause (default true)
:stacktrace - Print a stacktrace for the exception (default true)
:pretty-stacktrace - Print a stacktrace for the exception, formatted using io.aviso/pretty (default false)

You can also set the default values for these options by binding or resetting
arachne.error/*default-explain-opts*

format-date

(format-date date)
Convert a java.util.Date to a human-readable UTC string

log-error

macro

(log-error & [msg ex-data cause])
Log (but do not throw) an error message lookup using the specified error
message key, optional cause, and ex-data map. The message string may contain
:keywords which will be replaced by their corresponding values from the
ex-data, if present.

This is implemented as a macro so as to not show up in stack traces.

utc-date-format

Common UTC SimpleDateFormat to be used when reporting timestamps

wrap-error

macro

(wrap-error body types throw-type ex-data)
Utility to catch and re-throw errors with a more specific message.

Evaluates the body expression. If an exception is thrown, and it is one of the
type specified by `types`, then throw an ArachneException of the specified
type and ex-data.

Types may be either an exception class, or a value of :arachne.error/type in
an ArachneException.