From: Jérôme Benoit Date: Sun, 16 Jul 2023 22:57:44 +0000 (+0200) Subject: fix: ensure configuration section cache is always initialized X-Git-Tag: v1.2.18~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c1c97db8708f26af10385f6e86af7cd933891bb8;p=e-mobility-charging-stations-simulator.git fix: ensure configuration section cache is always initialized Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index ae3d8e9f..66abd3e1 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -52,6 +52,34 @@ export class Configuration { } public static getConfigurationSection(sectionName: ConfigurationSection): T { + if (!Configuration.configurationSectionCache.has(sectionName)) { + switch (sectionName) { + case ConfigurationSection.log: + Configuration.configurationSectionCache.set(sectionName, Configuration.buildLogSection()); + break; + case ConfigurationSection.performanceStorage: + Configuration.configurationSectionCache.set( + sectionName, + Configuration.buildPerformanceStorageSection(), + ); + break; + case ConfigurationSection.worker: + Configuration.configurationSectionCache.set( + sectionName, + Configuration.buildWorkerSection(), + ); + break; + case ConfigurationSection.uiServer: + Configuration.configurationSectionCache.set( + sectionName, + Configuration.buildUIServerSection(), + ); + break; + default: + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + throw new Error(`Unknown configuration section '${sectionName}'`); + } + } return Configuration.configurationSectionCache.get(sectionName) as T; }