You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
4 years ago
|
import { red, bgRed } from '../external/std.ts'
|
||
|
import { Service } from '../../../di/src/decorator/Service.ts'
|
||
|
import { Logging } from '../service/logging/Logging.ts'
|
||
|
|
||
|
@Service()
|
||
|
export default class RunLevelErrorHandler {
|
||
|
constructor(
|
||
|
protected logger: Logging,
|
||
|
) {}
|
||
|
|
||
|
get handle(): (e: Error) => void {
|
||
|
return (e: Error) => {
|
||
|
this.display(e)
|
||
|
Deno.exit(1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
display(e: Error) {
|
||
|
try {
|
||
|
const error_string = `RunLevelErrorHandler invoked:
|
||
|
|
||
|
${bgRed(' ')}
|
||
|
${bgRed(' UNCAUGHT TOP-LEVEL ERROR ')}
|
||
|
${bgRed(' ')}
|
||
|
|
||
|
${e.constructor ? e.constructor.name : e.name}
|
||
|
${red(`---------------------------------------------------`)}
|
||
|
${e.stack}
|
||
|
`
|
||
|
this.logger.error(error_string, true)
|
||
|
} catch (display_e) {
|
||
|
// The error display encountered an error...
|
||
|
// just throw the original so it makes it out
|
||
|
console.error('RunLevelErrorHandler encountered an error:', display_e.message)
|
||
|
throw e
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|