tera icon indicating copy to clipboard operation
tera copied to clipboard

Human readable representation of Error or Error JSON

Open samuelcolvin opened this issue 4 years ago • 2 comments

Tera is great, thank you so much.

Given that tera is useful when rendering user generated templates, it would be great if there was a simple way of generating a human readable description of an error.

Currently I'm using

match tera.add_raw_template(&t.name, &t.content) {
    Err(e) => return Err(SyntaxError::new(&format!("Invalid template {}: {:?}", t.name, e)).into()),
    Ok(v) => v,
};

The {:?} gives me details on the error but isn't particularly user friendly.

I know I can inspect e.kind and eventually build a better representation, but it would be great if tera came with this included - I imagine it's something many people would use.

For me it would also work to have an e.json() method which returned data about the error in JSON which I could then render in HTML as a pretty error description.

Or both 😃 .

samuelcolvin avatar Jun 14 '20 12:06 samuelcolvin

It's tricky because some errors have a source and how to handle them is up to you, eg https://github.com/getzola/zola/blob/master/src/console.rs#L118-L123

Keats avatar Jun 15 '20 11:06 Keats

I get that, it's part of the reason it would be useful to have a utility method to help.

The most flexible solution would be a JSON string with details of the error, that way the rendering logic has complete flexibility about how to display the error to the end user.

samuelcolvin avatar Jun 15 '20 12:06 samuelcolvin