Sfoglia il codice sorgente

Merge pull request #1034 from nightscout/fix-forced-unwrap-crash

Fix crash from force-unwrap on orphaned PumpEventStored with nil bolus
Sam King 1 mese fa
parent
commit
a2d416fc5b
1 ha cambiato i file con 6 aggiunte e 3 eliminazioni
  1. 6 3
      Trio/Sources/APS/Storage/PumpHistoryStorage.swift

+ 6 - 3
Trio/Sources/APS/Storage/PumpHistoryStorage.swift

@@ -291,13 +291,16 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
     }
 
     func determineBolusEventType(for event: PumpEventStored) -> PumpEventStored.EventType {
-        if event.bolus!.isSMB {
+        guard let bolus = event.bolus else {
+            return event.type.flatMap({ PumpEventStored.EventType(rawValue: $0) }) ?? .bolus
+        }
+        if bolus.isSMB {
             return .smb
         }
-        if event.bolus!.isExternal {
+        if bolus.isExternal {
             return .isExternal
         }
-        return PumpEventStored.EventType(rawValue: event.type!) ?? PumpEventStored.EventType.bolus
+        return event.type.flatMap({ PumpEventStored.EventType(rawValue: $0) }) ?? .bolus
     }
 
     func getPumpHistoryNotYetUploadedToNightscout() async throws -> [NightscoutTreatment] {