Improve error messages
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index 37cd1e64d2693ae99436137aebe32df5a7cfe46e..eb437ab08cf5e6e81baa1e8bf69499133200e456 100644 (file)
@@ -35,7 +35,7 @@ const noChargingStationTemplatesExitCode = 2;
 
 export class Bootstrap {
   private static instance: Bootstrap | null = null;
-  private workerImplementation: WorkerAbstract<ChargingStationWorkerData> | null = null;
+  private workerImplementation: WorkerAbstract<ChargingStationWorkerData> | null;
   private readonly uiServer!: AbstractUIServer;
   private readonly storage!: Storage;
   private numberOfChargingStationTemplates!: number;
@@ -47,6 +47,7 @@ export class Bootstrap {
 
   private constructor() {
     this.started = false;
+    this.workerImplementation = null;
     this.workerScript = path.join(
       path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
       'charging-station',
@@ -146,10 +147,10 @@ export class Bootstrap {
       this.workerImplementation = null;
       this.uiServer?.stop();
       await this.storage?.close();
+      this.started = false;
     } else {
-      console.error(chalk.red('Trying to stop the charging stations simulator while not started'));
+      console.error(chalk.red('Cannot stop a not started charging stations simulator'));
     }
-    this.started = false;
   }
 
   public async restart(): Promise<void> {