Skip to content

Commit

Permalink
Merge pull request #115 from twokul/errors
Browse files Browse the repository at this point in the history
Re-throw compilation errors with additional information
  • Loading branch information
stefanpenner committed Jun 9, 2017
2 parents 31a474c + f979e62 commit a390bc3
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions index.js
Expand Up @@ -7,6 +7,20 @@ const crypto = require('crypto');
const stringify = require('json-stable-stringify');
const stripBom = require('strip-bom');

function rethrowBuildError(error) {
if (!error) { throw new Error('Unknown Error'); }

if (typeof error === 'string') {
throw new Error('[string exception]: ' + error);
} else {
// augment with location and type information and re-throw.
error.type = 'Template Compiler Error';
error.location = error.location && error.location.start;

throw error;
}
}

class TemplateCompiler extends Filter {
constructor(inputTree, _options) {
let options = _options || {};
Expand Down Expand Up @@ -58,10 +72,14 @@ class TemplateCompiler extends Filter {
}

processString(string, relativePath) {
return 'export default ' + utils.template(this.options.templateCompiler, stripBom(string), {
contents: string,
moduleName: relativePath
}) + ';';
try {
return 'export default ' + utils.template(this.options.templateCompiler, stripBom(string), {
contents: string,
moduleName: relativePath
}) + ';';
} catch(error) {
rethrowBuildError(error);
}
}

_buildOptionsForHash() {
Expand Down

0 comments on commit a390bc3

Please sign in to comment.