cli: Print filename in question that throws during import
This commit is contained in:
parent
970c76fd10
commit
d4a23326ce
2 changed files with 11 additions and 5 deletions
4
cli.mjs
4
cli.mjs
|
@ -50,8 +50,8 @@ cli.processTargets().then(function() {
|
||||||
})
|
})
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
console.log('')
|
console.log('')
|
||||||
console.error('\x1b[31mUnknown error while opening files\x1b[0m')
|
console.error('\x1b[31m' + err.message + '\x1b[0m')
|
||||||
printError(err)
|
printError(err.inner)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
|
12
lib/cli.mjs
12
lib/cli.mjs
|
@ -62,9 +62,15 @@ CLI.prototype.loadFiles = async function() {
|
||||||
|
|
||||||
for (let i = 0; i < this.files.length; i++) {
|
for (let i = 0; i < this.files.length; i++) {
|
||||||
if (this.files[i].endsWith('.mjs') || this.files[i].endsWith('.js')) {
|
if (this.files[i].endsWith('.mjs') || this.files[i].endsWith('.js')) {
|
||||||
this.e.setFilename(this.files[i])
|
try {
|
||||||
await import('file:///' + path.join(cwd, this.files[i]))
|
this.e.setFilename(this.files[i])
|
||||||
this.e.resetFilename()
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue