cli: Print filename in question that throws during import

This commit is contained in:
Jonatan Nilsson 2021-06-02 15:31:09 +00:00
parent 970c76fd10
commit d4a23326ce
2 changed files with 11 additions and 5 deletions

View file

@ -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) {

View file

@ -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')) {
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
}
}
}
}