template-eyre

An error reporter for panics and eyre::Report with handlebars template support.

Ever used eyre and finding existing handlers too boring or complex? This crate enables you to customize your error report and add custom fields in seconds.

Features

Write your own template

This crate includes two templates Hook::simple and Hook::colored_simple, but you can always create your own templates easily!

First, get started by reading the handlebars guide. Handlebars is a simple template language, so this won't be hard.

Next, start writing your own template! You may gain some idea from builtin templates.

Notice that this crate provides you with some handy helpers. Also, the handlebars crate this crate depends on also has some custom helpers.

Example

A minimal handler can be built with a template like this:

```handlebars Oh no, this program crashed!

{{style "red" error}} {{*set multi=(gt (len sources) 1)}} {{#each sources}} {{#if @first}} {{style "black.bright" "Caused by:"}} {{/if}} {{indent (_if @root.multi @index null) (style "yellow" this)}} {{/each}}

{{style "cyan" "Please report this issue to ..."}} ```

and you get a flavored error report:

snapshot

Additional helpers

style helper

Color the output. Styles should be written at its "dotted" form.

See console's document for details.

e.g, {{style "black.bold.on_red" error}}

indent helper

Indent a block.

This helper has three forms:

e.g, {{indent @index this}}

inline _if helper

Inline version of if helper.

e.g, {{_if success "Yay!" "Oops!"}}

set decorator

Set local variables.

e.g, {{*set flag=true}}

License

This project is licensed under MIT License.