From 339b2e1ceb76cd8e64e946379028782656b30015 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 30 Sep 2015 15:33:28 -0400 Subject: [PATCH] include module ID in error message (#143) --- src/Module.js | 1 + test/function/reports-syntax-error-locations/_config.js | 8 ++++++++ test/function/reports-syntax-error-locations/main.js | 1 + 3 files changed, 10 insertions(+) create mode 100644 test/function/reports-syntax-error-locations/_config.js create mode 100644 test/function/reports-syntax-error-locations/main.js diff --git a/src/Module.js b/src/Module.js index 135eb13..cd372e0 100644 --- a/src/Module.js +++ b/src/Module.js @@ -552,6 +552,7 @@ export default class Module { } catch ( err ) { err.code = 'PARSE_ERROR'; err.file = this.id; // see above - not necessarily true, but true enough + err.message += ` in ${this.id}`; throw err; } } diff --git a/test/function/reports-syntax-error-locations/_config.js b/test/function/reports-syntax-error-locations/_config.js new file mode 100644 index 0000000..2cb1085 --- /dev/null +++ b/test/function/reports-syntax-error-locations/_config.js @@ -0,0 +1,8 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'reports syntax error filename', + error: function ( err ) { + assert.ok( /in .+main\.js/.test( err.message ) ); + } +}; diff --git a/test/function/reports-syntax-error-locations/main.js b/test/function/reports-syntax-error-locations/main.js new file mode 100644 index 0000000..d24584b --- /dev/null +++ b/test/function/reports-syntax-error-locations/main.js @@ -0,0 +1 @@ +var 42 = answer;