From aed9d51bbf05f696154b440cb2f46392484c5e37 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 27 Sep 2019 11:47:28 -0400 Subject: [PATCH] deps: handlebars@4.3.3 fixes #176 closes #175 closes #178 closes #179 --- HISTORY.md | 4 +++- lib/hbs.js | 25 +++++++++++++++++++------ package.json | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 21e363e..7d9eab6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,9 @@ unreleased * Fix async helpers not working when cache enabled * Fix handling of exceptions from layout * Fix handling of exceptions when cache enabled - * deps: handlebars@4.1.2 + * deps: handlebars@4.3.3 + - Block calling `helperMissing` and `blockHelperMissing` from templates + - Fix work-around for `constructor` blocking * deps: walk@2.3.14 4.0.4 / 2019-04-14 diff --git a/lib/hbs.js b/lib/hbs.js index eabea94..ed941a3 100644 --- a/lib/hbs.js +++ b/lib/hbs.js @@ -56,8 +56,7 @@ function middleware(filename, options, cb) { cb(null, res) }) } catch (err) { - err.message = filename + ': ' + err.message - cb(err) + cb(prependFilenameToError(filename, err)) } return @@ -83,8 +82,7 @@ function middleware(filename, options, cb) { cb(null, res); }); } catch (err) { - err.message = filename + ': ' + err.message; - cb(err); + cb(prependFilenameToError(filename, err)) } }); } @@ -108,8 +106,7 @@ function middleware(filename, options, cb) { cb(null, res) }) } catch (err) { - err.message = filename + ': ' + err.message - cb(err) + cb(prependFilenameToError(filename, err)) } }); } @@ -151,6 +148,22 @@ function middleware(filename, options, cb) { // TODO check if layout path has .hbs extension + function prependFilenameToError (filename, err) { + // prepend to the message + err.message = filename + ': ' + err.message + + // restore error message on stack (https://github.com/wycats/handlebars.js/issues/1562) + if (typeof err.stack === 'string' && err.stack.indexOf(err.name + '\n') === 0 && err.stack.indexOf(err.message) === -1) { + Object.defineProperty(err, 'stack', { + configurable: true, + value: err.name + ': ' + err.message, + writable: true + }) + } + + return err + } + function cacheAndCompile(filename, str) { var layout_template = handlebars.compile(str); if (options.cache) { diff --git a/package.json b/package.json index b4a83aa..848cc43 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "repository": "pillarjs/hbs", "main": "lib/hbs.js", "dependencies": { - "handlebars": "4.1.2", + "handlebars": "4.3.3", "walk": "2.3.14" }, "devDependencies": {