-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
I think it would be really cool, if the error message would be colored, so it can be read a bit better in the terminal.
I have a proof of concept running, and the output in Jest looks like this:
- for syntax error
which is night and day compared to the current messages without any highlighting.
My implementation is super naive based on Vincit/objection.js#1621 (comment)
async execute() {
let p
try {
p = await super.execute()
} catch (err) {
if (this._asyncStack) {
const originalStack = err.stack.split('\n').slice(7)
const newStack: string = originalStack
.concat(this._asyncStack)
.join('\n')
const nativeErrPosition = Number(err.nativeError?.position)
if (nativeErrPosition) {
const offset = -1
const { message } = err
const beforeSyntaxErr = highlight(
message.substring(0, nativeErrPosition + offset),
{
language: 'sql',
ignoreIllegals: true
}
)
const withSytaxErrorHighlighted =
beforeSyntaxErr +
chalk.blue.bgRed.bold(
message.substring(
nativeErrPosition + offset,
nativeErrPosition + offset + 1
)
) +
chalk.yellow(
message.substring(nativeErrPosition + offset + 1, message.length)
)
err.message = withSytaxErrorHighlighted
} else if (err instanceof DBError) {
err.message = highlight(err.message, {
language: 'sql',
ignoreIllegals: true
})
}
err.stack = newStack
}
throw err
}
return p
}
Metadata
Metadata
Assignees
Labels
No labels