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

Commit d05a565

Browse files
committed
beautiful and helpful error reporting during underscore template rendering
1 parent 9e5cec6 commit d05a565

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/engine_underscore.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@
2121
"use strict";
2222

2323
var _ = require('underscore');
24+
2425
var partialRegistry = {};
2526
var errorStyling = `
2627
<style>
27-
body {
28+
.plError {
2829
background: linear-gradient(to bottom, #f1f1f1 0%,#ffffff 60%);
2930
color: #444;
3031
padding: 30px;
3132
}
32-
h1 {
33+
.plError h1 {
3334
font-size: 16pt;
3435
color: #733;
3536
background: #fcfcfc;
3637
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
3738
padding: 17px 30px;
3839
margin: -30px -30px 0 -30px;
3940
}
40-
dt { font-weight: bold; }
41+
.plError dt { font-weight: bold; }
4142
</style>
4243
`;
4344

45+
4446
// extend underscore with partial-ing methods and other necessary tooling
4547
// HANDLESCORE! UNDERBARS!
4648

@@ -110,23 +112,21 @@ var engine_underscore = {
110112
// such will throw very real exceptions that will shatter the whole build
111113
// process if we don't handle them.
112114
try {
113-
// console.log('got here for pattern', pattern.patternName, pattern.extendedTemplate);
114-
// console.log('testing:', _.template('<%- foo %>')({foo: 'bar'}));
115-
// console.log('data:', data);
116115
renderedHTML = compiled(_.extend(data || {}, {
117116
_allData: data,
118117
_partials: partials
119118
}));
120119
} catch (e) {
121120
var errorMessage = `Error rendering underscore pattern "${pattern.patternName}" (${pattern.relPath}): [${e.toString()}]`;
122121
console.log(errorMessage);
123-
renderedHTML = `${errorStyling}
122+
renderedHTML = `${errorStyling} <div class="plError">
124123
<h1>Error rendering underscore pattern "${pattern.patternName}"</h1>
125124
<dl>
126-
<dt>Message</dt><dd>${e.toString()}</dd>
127-
<dt>Partial name</dt><dd>${pattern.patternName}</dd>
128-
<dt>Template path</dt><dd>${pattern.relPath}</dd>
125+
<dt>Message</dt><dd>${e.toString()}</dd>
126+
<dt>Partial name</dt><dd>${pattern.patternName}</dd>
127+
<dt>Template path</dt><dd>${pattern.relPath}</dd>
129128
</dl>
129+
</div>
130130
`;
131131
}
132132

0 commit comments

Comments
 (0)