handle unhandled errors
This commit is contained in:
parent
c7bf60bd61
commit
0513c9827e
18
package-lock.json
generated
18
package-lock.json
generated
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@squeebot/cli",
|
"name": "@squeebot/cli",
|
||||||
"version": "3.4.3",
|
"version": "3.4.4",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@squeebot/cli",
|
"name": "@squeebot/cli",
|
||||||
"version": "3.4.3",
|
"version": "3.4.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@squeebot/core": "^3.3.6",
|
"@squeebot/core": "^3.3.8",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"node-watch": "^0.7.1",
|
"node-watch": "^0.7.1",
|
||||||
"tar": "^6.1.11",
|
"tar": "^6.1.11",
|
||||||
@ -144,9 +144,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@squeebot/core": {
|
"node_modules/@squeebot/core": {
|
||||||
"version": "3.3.6",
|
"version": "3.3.8",
|
||||||
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.8.tgz",
|
||||||
"integrity": "sha512-a2o6h0fVBpSWpsrX1OBrFTjKMtkX5LQLm9i738sarMFK/q84zFmf/hKvpTNi71gviP1tEOB/gqat/AmohzvLSw==",
|
"integrity": "sha512-7ZvpbnEX2mUR76LyB4UFYpJ1pAmuI0sDNop/jHKki7JJqqcnKi3uDb6KC7dedLRKVTMIWCAbvSR9J+C04+v1JA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dateformat": "^4.5.1",
|
"dateformat": "^4.5.1",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
@ -1973,9 +1973,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@squeebot/core": {
|
"@squeebot/core": {
|
||||||
"version": "3.3.6",
|
"version": "3.3.8",
|
||||||
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/@squeebot/core/-/core-3.3.8.tgz",
|
||||||
"integrity": "sha512-a2o6h0fVBpSWpsrX1OBrFTjKMtkX5LQLm9i738sarMFK/q84zFmf/hKvpTNi71gviP1tEOB/gqat/AmohzvLSw==",
|
"integrity": "sha512-7ZvpbnEX2mUR76LyB4UFYpJ1pAmuI0sDNop/jHKki7JJqqcnKi3uDb6KC7dedLRKVTMIWCAbvSR9J+C04+v1JA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"dateformat": "^4.5.1",
|
"dateformat": "^4.5.1",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@squeebot/cli",
|
"name": "@squeebot/cli",
|
||||||
"version": "3.4.3",
|
"version": "3.4.4",
|
||||||
"description": "Squeebot v3 runtime, environments and configuration",
|
"description": "Squeebot v3 runtime, environments and configuration",
|
||||||
"main": "dist/squeebot.js",
|
"main": "dist/squeebot.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@ -30,7 +30,7 @@
|
|||||||
"typescript": "^4.4.2"
|
"typescript": "^4.4.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@squeebot/core": "^3.3.6",
|
"@squeebot/core": "^3.3.8",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"node-watch": "^0.7.1",
|
"node-watch": "^0.7.1",
|
||||||
"tar": "^6.1.11",
|
"tar": "^6.1.11",
|
||||||
|
16
src/core.ts
16
src/core.ts
@ -78,6 +78,22 @@ export class Squeebot implements ISqueebotCore {
|
|||||||
this.stream.on('core', 'request-core', (pl: string) =>
|
this.stream.on('core', 'request-core', (pl: string) =>
|
||||||
this.stream.emitTo(pl, 'core', this));
|
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
|
// Start enabled plugins
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
await this.startPlugins();
|
await this.startPlugins();
|
||||||
|
Loading…
Reference in New Issue
Block a user