handle unhandled errors

This commit is contained in:
Evert Prants 2022-08-25 21:20:36 +03:00
parent c7bf60bd61
commit 0513c9827e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 27 additions and 11 deletions

18
package-lock.json generated
View File

@ -1,15 +1,15 @@
{
"name": "@squeebot/cli",
"version": "3.4.3",
"version": "3.4.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@squeebot/cli",
"version": "3.4.3",
"version": "3.4.4",
"license": "MIT",
"dependencies": {
"@squeebot/core": "^3.3.6",
"@squeebot/core": "^3.3.8",
"fs-extra": "^10.0.0",
"node-watch": "^0.7.1",
"tar": "^6.1.11",
@ -144,9 +144,9 @@
}
},
"node_modules/@squeebot/core": {
"version": "3.3.6",
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.6.tgz",
"integrity": "sha512-a2o6h0fVBpSWpsrX1OBrFTjKMtkX5LQLm9i738sarMFK/q84zFmf/hKvpTNi71gviP1tEOB/gqat/AmohzvLSw==",
"version": "3.3.8",
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.8.tgz",
"integrity": "sha512-7ZvpbnEX2mUR76LyB4UFYpJ1pAmuI0sDNop/jHKki7JJqqcnKi3uDb6KC7dedLRKVTMIWCAbvSR9J+C04+v1JA==",
"dependencies": {
"dateformat": "^4.5.1",
"fs-extra": "^10.0.0",
@ -1973,9 +1973,9 @@
}
},
"@squeebot/core": {
"version": "3.3.6",
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.6.tgz",
"integrity": "sha512-a2o6h0fVBpSWpsrX1OBrFTjKMtkX5LQLm9i738sarMFK/q84zFmf/hKvpTNi71gviP1tEOB/gqat/AmohzvLSw==",
"version": "3.3.8",
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.8.tgz",
"integrity": "sha512-7ZvpbnEX2mUR76LyB4UFYpJ1pAmuI0sDNop/jHKki7JJqqcnKi3uDb6KC7dedLRKVTMIWCAbvSR9J+C04+v1JA==",
"requires": {
"dateformat": "^4.5.1",
"fs-extra": "^10.0.0",

View File

@ -1,6 +1,6 @@
{
"name": "@squeebot/cli",
"version": "3.4.3",
"version": "3.4.4",
"description": "Squeebot v3 runtime, environments and configuration",
"main": "dist/squeebot.js",
"bin": {
@ -30,7 +30,7 @@
"typescript": "^4.4.2"
},
"dependencies": {
"@squeebot/core": "^3.3.6",
"@squeebot/core": "^3.3.8",
"fs-extra": "^10.0.0",
"node-watch": "^0.7.1",
"tar": "^6.1.11",

View File

@ -78,6 +78,22 @@ export class Squeebot implements ISqueebotCore {
this.stream.on('core', 'request-core', (pl: string) =>
this.stream.emitTo(pl, 'core', this));
// Handle uncaught exceptions to prevent the whole bot from getting bricked
process.on('uncaughtException', (err) => {
logger.error('Process caught an unhandled exception:', err.stack);
this.stream.emit('error', err);
});
// Handle uncaught rejections to prevent the whole bot from getting bricked
process.on('unhandledRejection', (reason, promise) => {
logger.error('Process caught an unhandled promise rejection:', reason);
logger.error('In promise:', promise);
const error = new Error(reason?.toString());
error.name = 'unhandledRejection';
this.stream.emit('error', error);
});
// Start enabled plugins
if (autostart) {
await this.startPlugins();