From 8dbb284bf422da7d4a46ab9a0fd532d7e0844794 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 12 Oct 2024 12:46:23 +0100 Subject: [PATCH] Prevented server from running when an invalid/corrupt config json is found --- project/src/servers/ConfigServer.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/project/src/servers/ConfigServer.ts b/project/src/servers/ConfigServer.ts index 51351f0d..7c553317 100644 --- a/project/src/servers/ConfigServer.ts +++ b/project/src/servers/ConfigServer.ts @@ -41,10 +41,21 @@ export class ConfigServer { if (this.acceptableFileExtensions.includes(this.vfs.getFileExtension(file.toLowerCase()))) { const fileName = this.vfs.stripExtension(file); const filePathAndName = `${filepath}${file}`; - this.configs[`spt-${fileName}`] = this.jsonUtil.deserializeJsonC( + const deserialsiedJson = this.jsonUtil.deserializeJsonC( this.vfs.readFile(filePathAndName), filePathAndName, ); + + if (!deserialsiedJson) { + this.logger.error( + `Config file: ${filePathAndName} is corrupt. Use a site like: https://jsonlint.com to find the issue.`, + ); + throw new Error( + `Server will not run until the: ${filePathAndName} config error mentioned above is fixed`, + ); + } + + this.configs[`spt-${fileName}`] = deserialsiedJson; } }