From d4a23326cecb06abfa47d391b224041b52fee594 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Wed, 2 Jun 2021 15:31:09 +0000 Subject: [PATCH] cli: Print filename in question that throws during import --- cli.mjs | 4 ++-- lib/cli.mjs | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) 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 + } } } }