Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 94f0a09

Browse files
committed
Improve error handling: if a requested pattern partial is missing, say
so; if there's compilation error, print the output from the exception.
1 parent c16cf25 commit 94f0a09

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/engine_underscore.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ function addParentContext(data, currentContext) {
3232

3333
_.mixin({
3434
renderNamedPartial: function (partialKey, data, currentContext) {
35-
return _.renderPartial(partialRegistry[partialKey], data, currentContext);
35+
var partialString = partialRegistry[partialKey];
36+
if (typeof partialString !== 'string') { throw `Pattern ${partialKey} not found.`; }
37+
38+
return _.renderPartial(partialString, data, currentContext);
3639
},
3740
renderPartial: function (partial, dataIn, currentContext) {
3841
var data = dataIn || {};
@@ -81,7 +84,7 @@ var engine_underscore = {
8184
try {
8285
compiled = _.template(pattern.extendedTemplate);
8386
} catch (e) {
84-
console.log(`Error compiling template ${pattern.patternName}:`, pattern.extendedTemplate);
87+
console.log(`Error compiling underscore template ${pattern.patternName}:`, pattern.extendedTemplate, e);
8588
}
8689

8790
// This try-catch is necessary because references to undefined variables

0 commit comments

Comments
 (0)