Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Last active December 18, 2015 17:39
Show Gist options
  • Save fengmk2/5819783 to your computer and use it in GitHub Desktop.
Save fengmk2/5819783 to your computer and use it in GitHub Desktop.
var __stack = { lineno: 1, input: "<%- this.name %>", filename: "options.scope.html" };
function rethrow(err, str, filename, lineno){
var lines = str.split('\n')
, start = Math.max(lineno - 3, 0)
, end = Math.min(lines.length, lineno + 3);
// Error context
var context = lines.slice(start, end).map(function(line, i){
var curr = i + start + 1;
return (curr == lineno ? ' >> ' : ' ')
+ curr
+ '| '
+ line;
}).join('\n');
// Alter exception message
err.path = filename;
err.message = (filename || 'ejs') + ':'
+ lineno + '\n'
+ context + '\n\n'
+ err.message;
throw err;
}
try {
var buf = [];
with (locals || {}) {
buf.push('', (__stack.lineno=1, this.name ), '');
}
return buf.join('');
} catch (err) {
rethrow(err, __stack.input, __stack.filename, __stack.lineno);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment