Skip to content

Commit aed9d51

Browse files
committed
fixes #176 closes #175 closes #178 closes #179
1 parent 2f12c5e commit aed9d51

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

HISTORY.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ unreleased
44
* Fix async helpers not working when cache enabled
55
* Fix handling of exceptions from layout
66
* Fix handling of exceptions when cache enabled
7-
7+
8+
- Block calling `helperMissing` and `blockHelperMissing` from templates
9+
- Fix work-around for `constructor` blocking
810
911

1012
4.0.4 / 2019-04-14

lib/hbs.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ function middleware(filename, options, cb) {
5656
cb(null, res)
5757
})
5858
} catch (err) {
59-
err.message = filename + ': ' + err.message
60-
cb(err)
59+
cb(prependFilenameToError(filename, err))
6160
}
6261

6362
return
@@ -83,8 +82,7 @@ function middleware(filename, options, cb) {
8382
cb(null, res);
8483
});
8584
} catch (err) {
86-
err.message = filename + ': ' + err.message;
87-
cb(err);
85+
cb(prependFilenameToError(filename, err))
8886
}
8987
});
9088
}
@@ -108,8 +106,7 @@ function middleware(filename, options, cb) {
108106
cb(null, res)
109107
})
110108
} catch (err) {
111-
err.message = filename + ': ' + err.message
112-
cb(err)
109+
cb(prependFilenameToError(filename, err))
113110
}
114111
});
115112
}
@@ -151,6 +148,22 @@ function middleware(filename, options, cb) {
151148

152149
// TODO check if layout path has .hbs extension
153150

151+
function prependFilenameToError (filename, err) {
152+
// prepend to the message
153+
err.message = filename + ': ' + err.message
154+
155+
// restore error message on stack (https://github.com/wycats/handlebars.js/issues/1562)
156+
if (typeof err.stack === 'string' && err.stack.indexOf(err.name + '\n') === 0 && err.stack.indexOf(err.message) === -1) {
157+
Object.defineProperty(err, 'stack', {
158+
configurable: true,
159+
value: err.name + ': ' + err.message,
160+
writable: true
161+
})
162+
}
163+
164+
return err
165+
}
166+
154167
function cacheAndCompile(filename, str) {
155168
var layout_template = handlebars.compile(str);
156169
if (options.cache) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"repository": "pillarjs/hbs",
1111
"main": "lib/hbs.js",
1212
"dependencies": {
13-
"handlebars": "4.1.2",
13+
"handlebars": "4.3.3",
1414
"walk": "2.3.14"
1515
},
1616
"devDependencies": {

0 commit comments

Comments
 (0)