Expand description

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

  • Handlebars powered error reports
  • Color support
  • Custom indent support
  • Sensible bundled handlers
  • Backtrace support
  • Panic handler
  • Custom fields support

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:

Oh no, this program crashed!

{{style "red" error}}
{{*set multi=(gt (len sources) 1)}}
{{#each sources}}
    {{#if @first}}
        {{~style "dim" "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:

  • indent content - Indent the content by four spaces.
  • indent <number> content - Insert a number before the first line with the same indentation level as backtraces.
  • indent <string> content - Insert given string before every line.

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}}

concat helper

Concatenate strings.

E.g., {{concat "a" "b"}}

License

This project is licensed under MIT License.

Modules

Helpers for adding custom fields to error reports

Structs

An eyre error handler which reports errors with given handlebars templates.

An eyre reporting hook.