chore: improve handling when config.json is missing & fix logger options #1460
@ -64,5 +64,11 @@ export const config: IConfig = {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const loadConfig = (): void => {
 | 
					export const loadConfig = (): void => {
 | 
				
			||||||
 | 
					    // Set all values to undefined now so if the new config.json omits some fields that were previously present, it's correct in-memory.
 | 
				
			||||||
 | 
					    for (const key of Object.keys(config)) {
 | 
				
			||||||
 | 
					        // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
 | 
				
			||||||
 | 
					        (config as any)[key] = undefined;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8")));
 | 
					    Object.assign(config, JSON.parse(fs.readFileSync(configPath, "utf-8")));
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -9,13 +9,6 @@ fs.watchFile(configPath, () => {
 | 
				
			|||||||
        amnesia = false;
 | 
					        amnesia = false;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        logger.info("Detected a change to config.json, reloading its contents.");
 | 
					        logger.info("Detected a change to config.json, reloading its contents.");
 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Set all values to undefined now so if the new config.json omits some fields that were previously present, it's correct in-memory.
 | 
					 | 
				
			||||||
        for (const key of Object.keys(config)) {
 | 
					 | 
				
			||||||
            // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
 | 
					 | 
				
			||||||
            (config as any)[key] = undefined;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            loadConfig();
 | 
					            loadConfig();
 | 
				
			||||||
        } catch (e) {
 | 
					        } catch (e) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user