mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Treat unhandled errors as fatal
All possible Promise rejections and exception bubbling should be handled by either the code creating the exception or the code invoking the operation that could fail. Treat therefore uncaught exceptions and unhandled promise rejetions as fatal errors that log a traceback and immedately terminate the Node.js process.
This commit is contained in:
1 parent
27633d51b6
commit
50703f8ae6
4 files changed
+17
-3
No files matched your search
@@ -187,6 +187,7 @@ async function startControl() {
|
||||
level: args.logLevel,
|
||||
format: new libLoggingUtils.TerminalFormat(),
|
||||
}));
|
||||
libLoggingUtils.handleUnhandledErrors(logger);
|
||||
|
||||
logger.verbose(`Loading available plugins from ${args.pluginList}`);
|
||||
let pluginList = new Map();
|
||||
|
||||
@@ -458,11 +458,25 @@ async function migrateLogs(log, directory, pattern) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleUnhandledErrors() {
|
||||
/* eslint-disable node/no-process-exit */
|
||||
process.on("uncaughtException", err => {
|
||||
logger.fatal(`Uncaught exception:\n${err.stack}`);
|
||||
process.exit(1);
|
||||
});
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
logger.fatal(`Unhandled rejection:\n${reason.stack ? reason.stack : reason}`);
|
||||
process.exit(1);
|
||||
});
|
||||
/* eslint-enable node/no-process-exit */
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
TerminalFormat,
|
||||
LinkTransport,
|
||||
LogIndex,
|
||||
handleUnhandledErrors,
|
||||
queryLog,
|
||||
migrateLogs,
|
||||
|
||||
|
||||
@@ -284,6 +284,7 @@ async function initialize() {
|
||||
format: new libLoggingUtils.TerminalFormat(),
|
||||
}));
|
||||
}
|
||||
libLoggingUtils.handleUnhandledErrors(logger);
|
||||
|
||||
let command = parameters.args._[0];
|
||||
if (command === "run") {
|
||||
@@ -355,9 +356,6 @@ async function startup() {
|
||||
// and as the process name in ps/top on linux.
|
||||
process.title = "clusterioMaster";
|
||||
|
||||
// add better stack traces on promise rejection
|
||||
process.on("unhandledRejection", err => logger.error(`Unhandled rejection:\n${err.stack}`));
|
||||
|
||||
let { args, shouldRun, clusterLogger, pluginInfos, masterConfigPath, masterConfig } = await initialize();
|
||||
if (!shouldRun) {
|
||||
return;
|
||||
|
||||
@@ -129,6 +129,7 @@ async function startSlave() {
|
||||
filter: info => info.instance_id === undefined,
|
||||
}));
|
||||
}
|
||||
libLoggingUtils.handleUnhandledErrors(logger);
|
||||
|
||||
let command = args._[0];
|
||||
if (command === "run") {
|
||||
|
||||
Reference in new issue
Block a user