tera
tera copied to clipboard
Human readable representation of Error or Error JSON
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 😃 .
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
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.