fix: avoid null exception at firmware upgrade
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 9 Dec 2023 20:08:44 +0000 (21:08 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 9 Dec 2023 20:08:44 +0000 (21:08 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index d6ca68745cddfdf075aea10fbaa6b5df057c417f..5bc0ec9ad24d8ae76f486f388eb86d03a2cad0b8 100644 (file)
@@ -1200,14 +1200,16 @@ export class ChargingStation extends EventEmitter {
         this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ??
         this.stationInfo.firmwareVersion?.split('.').length;
       const match = new RegExp(this.stationInfo.firmwareVersionPattern!)
-        .exec(this.stationInfo.firmwareVersion!)!
-        .slice(1, patternGroup! + 1);
-      const patchLevelIndex = match.length - 1;
-      match[patchLevelIndex] = (
-        convertToInt(match[patchLevelIndex]) +
-        this.stationInfo.firmwareUpgrade!.versionUpgrade!.step!
-      ).toString();
-      this.stationInfo.firmwareVersion = match?.join('.');
+        .exec(this.stationInfo.firmwareVersion!)
+        ?.slice(1, patternGroup! + 1);
+      if (!isNullOrUndefined(match)) {
+        const patchLevelIndex = match!.length - 1;
+        match![patchLevelIndex] = (
+          convertToInt(match![patchLevelIndex]) +
+          this.stationInfo.firmwareUpgrade!.versionUpgrade!.step!
+        ).toString();
+        this.stationInfo.firmwareVersion = match!.join('.');
+      }
     }
     this.saveStationInfo();
     this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl();