返回提交历史
Modified
src/services/configService.ts
+3
-1
Modified
src/services/configWatcherService.ts
+2
-2
XFEstudio/XFESpaceNinjaServer
chore: continue execution if subsequent JSON.parse on config failed (#2353)
By calling JSON.parse before setting everything to undefined, we don't lose the old config in case of an error. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2353 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
1a2d8ab1
代码差异
2 个文件
+5
-3
@@ -103,11 +103,13 @@ export const config: IConfig = {
103
103
};
104
104
105
105
export const loadConfig = (): void => {
106
const newConfig = JSON.parse(fs.readFileSync(configPath, "utf-8")) as IConfig;
107
106
108
// Set all values to undefined now so if the new config.json omits some fields that were previously present, it's correct in-memory.
107
109
for (const key of Object.keys(config)) {
108
110
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
109
111
(config as any)[key] = undefined;
110
112
}
111
113
112
Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8")));
114
Object.assign(config, newConfig);
113
115
};
@@ -14,8 +14,8 @@ chokidar.watch(configPath).on("change", () => {
14
14
try {
15
15
loadConfig();
16
16
} catch (e) {
17
logger.error("FATAL ERROR: Config failed to be reloaded: " + (e as Error).message);
18
process.exit(1);
17
logger.error("Config changes were not applied: " + (e as Error).message);
18
return;
19
19
}
20
20
validateConfig();
21
21
syncConfigWithDatabase();