squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
571 stars 81 forks source link

Own Error handler if given data is invalid #190

Closed jase88 closed 3 years ago

jase88 commented 4 years ago

Is your feature request related to a problem? Please describe. Currently squirrelly throws an exception if invalid data has been passed toSqrl.render, which is totally fine as default.

Describe the solution you'd like It would be great to have the possibility to define a custom error handler, which might return a result instead of throwing

e.g.

Sqrl.render('Hello {{person.name}}', {person: null}, {useWith: true});
Sqrl.render('{{greeting}} {{person.name}}', {greeting: 'Hello'}, {useWith: true});

-> could both return 'Hello '

nebrelbug commented 4 years ago

@kerosin great question! Some simple error handling is possible with the try helper.

See https://runkit.com/nebrelbug/squirrelly-try-catch for an example :)