chore: improve error reporting when config.json exists with invalid json (#2166)
Reviewed-on: OpenWF/SpaceNinjaServer#2166 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									3053112428
								
							
						
					
					
						commit
						c6dd8bfb81
					
				@ -1,9 +1,14 @@
 | 
				
			|||||||
// First, init config.
 | 
					// First, init config.
 | 
				
			||||||
import { config, loadConfig } from "@/src/services/configService";
 | 
					import { config, loadConfig } from "@/src/services/configService";
 | 
				
			||||||
 | 
					import fs from "fs";
 | 
				
			||||||
try {
 | 
					try {
 | 
				
			||||||
    loadConfig();
 | 
					    loadConfig();
 | 
				
			||||||
} catch (e) {
 | 
					} catch (e) {
 | 
				
			||||||
    console.log("ERROR: Failed to load config.json. You can copy config.json.example to create your config.json.");
 | 
					    if (fs.existsSync("config.json")) {
 | 
				
			||||||
 | 
					        console.log("Failed to load config.json: " + (e as Error).message);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        console.log("Failed to load config.json. You can copy config.json.example to create your config.json.");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    process.exit(1);
 | 
					    process.exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ fs.watchFile(configPath, () => {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            loadConfig();
 | 
					            loadConfig();
 | 
				
			||||||
        } catch (e) {
 | 
					        } catch (e) {
 | 
				
			||||||
            logger.error("Failed to reload config.json. Did you delete it?! Execution cannot continue.");
 | 
					            logger.error("FATAL ERROR: Config failed to be reloaded: " + (e as Error).message);
 | 
				
			||||||
            process.exit(1);
 | 
					            process.exit(1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        validateConfig();
 | 
					        validateConfig();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user