Cannot read property 'match' of undefined - undecipherable error


#1

I want to port my Ghost theme to 2.0, but the error messages are completely unhelpful.
I’m getting a 500 in my default.hbs.

[default.hbs] Cannot read property 'match' of undefined.

It’s very likely a deprecated handlebar template, but I have absolutely zero way of finding out which one. Unless I completely empty out the default.hbs, the error doesn’t go away.
And the stacktraces aren’t helpful at all.

How am I supposed to resolve this?

InternalServerError: [default.hbs] Cannot read property 'match' of undefined
    at new GhostError (/var/www/arvid.io/versions/2.2.3/core/server/lib/common/errors.js:10:26)
    at _private.prepareError (/var/www/arvid.io/versions/2.2.3/core/server/web/shared/middlewares/error-handler.js:42:19)
    at Layer.handle_error (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/layer.js:71:5)
    at trim_prefix (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:315:13)
    at /var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:335:12)
    at next (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:275:10)
    at Layer.handle_error (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/layer.js:67:12)
    at trim_prefix (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:315:13)
    at /var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:275:10)
    at Immediate.<anonymous> (/var/www/arvid.io/versions/2.2.3/node_modules/express/lib/router/index.js:635:15)
    at runCallback (timers.js:812:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

TypeError: [default.hbs] Cannot read property 'match' of undefined
    at getAssetUrl (/var/www/arvid.io/versions/2.2.3/core/server/data/meta/asset_url.js:17:14)
    at Object.asset (/var/www/arvid.io/versions/2.2.3/core/server/helpers/asset.js:14:9)
    at Object.eval [as main] (eval at createFunctionContext (/var/www/arvid.io/versions/2.2.3/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:68)
    at main (/var/www/arvid.io/versions/2.2.3/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
    at ret (/var/www/arvid.io/versions/2.2.3/node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)
    at ret (/var/www/arvid.io/versions/2.2.3/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21)
    at renderTemplate (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:483:13)
    at _stackRenderer (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:524:9)
    at /var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:503:7
    at Function.Waiter.done (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/async.js:68:12)
    at renderTemplate (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:494:11)
    at render (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:531:5)
    at renderIt (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:593:18)
    at /var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:603:11
    at ExpressHbs.cacheLayout (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:121:31)
    at parseLayout (/var/www/arvid.io/versions/2.2.3/node_modules/express-hbs/lib/hbs.js:465:12)

#2

The asset helper is “broken”. It seems to require a string now.

{{asset css/styles.min.css}} is broken as of v2, while it was working fine before.
Raplace with {{asset "css/styles.min.css"}}.


#3

First - I agree that the indecipherable error could be better here - we should validate the helper input.

However, given what {{asset css/styles.min.css}} means in handlebars, I’m extremely surprised that it ever worked. Without passing the value as a string, handlebars will assume that css/styles.min.css is the key name of a local data property that it can access - i.e. it’ll look for data in your content that matches this key. As it wouldn’t find anything matching, my expectation would be that the helper would evaluate to null / an empty string rather than throw an error.

Also, the code that’s throwing the error also hasn’t changed in 2 years so for curiosities sake, what version did you last run your theme on?


#4

So am I.

I ran the theme last on 1.10.x. It worked just fine.