diff --git a/cli.mjs b/cli.mjs index f7dd5ac..a82992b 100644 --- a/cli.mjs +++ b/cli.mjs @@ -50,8 +50,8 @@ cli.processTargets().then(function() { }) }, function(err) { console.log('') - console.error('\x1b[31mUnknown error while opening files\x1b[0m') - printError(err) + console.error('\x1b[31m' + err.message + '\x1b[0m') + printError(err.inner) process.exit(1) }) }, function(err) { diff --git a/lib/cli.mjs b/lib/cli.mjs index 2455c2c..cb94113 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -62,9 +62,15 @@ CLI.prototype.loadFiles = async function() { for (let i = 0; i < this.files.length; i++) { if (this.files[i].endsWith('.mjs') || this.files[i].endsWith('.js')) { - this.e.setFilename(this.files[i]) - await import('file:///' + path.join(cwd, this.files[i])) - this.e.resetFilename() + try { + this.e.setFilename(this.files[i]) + await import('file:///' + path.join(cwd, this.files[i])) + this.e.resetFilename() + } catch (e) { + let newError = new Error(`Error while loading ${this.files[i]}`) + newError.inner = e + throw newError + } } } }