Skip to content

helperMissing and consistency for different expression types #783

@ErisDS

Description

@ErisDS

When first developing Ghost, I ran into the helperMissing helper. For our purposes, throwing an exception was a bit much, so I added an override to make it log the error and continue.

However I've since noticed that helperMissing only gets called if you pass something to the helper:

{{test}} won't cause helperMissing to be called
{{test "testing"}} will cause helperMissing to be called
{{#test}}{{/test}} will cause blockHelperMissing to be called

This means that in some cases, using a helper that doesn't exist throws an exception, and in others, it fails silently. I realise that in the 'fails silently' case the helper could in fact be a key or path.

Having researched this a little bit, I found an issue which indicates that missing keys should cause helperMissing to be called: #318. More recently, someone raised this issue (#586) and the answer seems to me to have overlooked the fact that #318 states this should work.

Furthermore it indicates that the solution should be to override escapeExpression - however escapeExpression doesn't have any context such as the name of the helper/key which was attempted to be called, so it isn't possible to output a useful error at this point.

Context:
My ultimate goal here is to capture all of the problems (be they exceptions or silent failures) in a handlebars template, throw exceptions in debug mode, and log warnings otherwise. This is to make developing Ghost themes a little bit nicer.

I believe it ought to be possible (even if it isn't the default) to capture all issues in a template in a consistent way, and deal with them as we please. Given that there is already helperMissing and blockHelperMissing perhaps there could be a keyMissing method that gets called if the key does not exist. This method could just be a pass-through by default, but at least then users of handlebars.js could choose to override that functionality if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions