fix: ensure configuration section cache is always initialized
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 16 Jul 2023 22:57:44 +0000 (00:57 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 16 Jul 2023 22:57:44 +0000 (00:57 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Configuration.ts

index ae3d8e9f186aeb47e89d71a97db1f84273c87cf5..66abd3e101dc6e427cac6c5c35babe61d9fdd02e 100644 (file)
@@ -52,6 +52,34 @@ export class Configuration {
   }
 
   public static getConfigurationSection<T>(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;
   }