Crates.io | template-eyre |
lib.rs | template-eyre |
version | 0.1.0-alpha.6 |
source | src |
created_at | 2022-01-13 16:18:15.398493 |
updated_at | 2022-01-19 15:55:02.55551 |
description | An error reporter for panics and `eyre::Report` with handlebars template support. |
homepage | |
repository | https://github.com/PhotonQuantum/template-eyre |
max_upload_size | |
id | 513390 |
size | 135,046 |
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.
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.
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:
style
helperColor 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
helperIndent 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}}
_if
helperInline version of if
helper.
E.g., {{_if success "Yay!" "Oops!"}}
set
decoratorSet local variables.
E.g., {{*set flag=true}}
concat
helperConcatenate strings.
E.g., {{concat "a" "b"}}
This project is licensed under MIT License.