@@ -612,7 +612,7 @@ extension LoopDataManager {
612612 _ = updateGroup. wait ( timeout: . distantFuture)
613613
614614 guard let lastGlucoseDate = latestGlucoseDate else {
615- throw LoopError . missingDataError ( details : " Glucose data not available " , recovery : " Check your CGM data source " )
615+ throw LoopError . missingDataError ( . glucose )
616616 }
617617
618618 let retrospectiveStart = lastGlucoseDate. addingTimeInterval ( - settings. retrospectiveCorrectionInterval)
@@ -738,7 +738,7 @@ extension LoopDataManager {
738738 dispatchPrecondition ( condition: . onQueue( dataAccessQueue) )
739739
740740 guard let basalRates = basalRateSchedule else {
741- throw LoopError . configurationError ( " Basal Rate Schedule " )
741+ throw LoopError . configurationError ( . basalRateSchedule )
742742 }
743743
744744 let pendingTempBasalInsulin : Double
@@ -765,11 +765,11 @@ extension LoopDataManager {
765765 dispatchPrecondition ( condition: . onQueue( dataAccessQueue) )
766766
767767 guard let model = insulinModelSettings? . model else {
768- throw LoopError . configurationError ( " Check settings " )
768+ throw LoopError . configurationError ( . insulinModel )
769769 }
770770
771771 guard let glucose = self . glucoseStore. latestGlucose else {
772- throw LoopError . missingDataError ( details : " Cannot predict glucose due to missing input data " , recovery : " Check your CGM data source " )
772+ throw LoopError . missingDataError ( . glucose)
773773 }
774774
775775 var momentum : [ GlucoseEffect ] = [ ]
@@ -810,13 +810,15 @@ extension LoopDataManager {
810810 */
811811 private func updateRetrospectiveGlucoseEffect( effectDuration: TimeInterval = TimeInterval ( minutes: 60 ) ) throws {
812812 dispatchPrecondition ( condition: . onQueue( dataAccessQueue) )
813+
814+ guard let carbEffect = self . carbEffect else {
815+ self . retrospectivePredictedGlucose = nil
816+ throw LoopError . missingDataError ( . carbEffect)
817+ }
813818
814- guard
815- let carbEffect = self . carbEffect,
816- let insulinEffect = self . insulinEffect
817- else {
819+ guard let insulinEffect = self . insulinEffect else {
818820 self . retrospectivePredictedGlucose = nil
819- throw LoopError . missingDataError ( details : " Cannot retrospect glucose due to missing input data " , recovery : nil )
821+ throw LoopError . missingDataError ( . insulinEffect )
820822 }
821823
822824 guard let change = retrospectiveGlucoseChange else {
@@ -858,12 +860,12 @@ extension LoopDataManager {
858860
859861 guard let glucose = glucoseStore. latestGlucose else {
860862 self . predictedGlucose = nil
861- throw LoopError . missingDataError ( details : " Glucose " , recovery : " Check your CGM data source " )
863+ throw LoopError . missingDataError ( . glucose )
862864 }
863865
864866 guard let pumpStatusDate = doseStore. lastReservoirValue? . startDate else {
865867 self . predictedGlucose = nil
866- throw LoopError . missingDataError ( details : " Reservoir " , recovery : " Check that your pump is in range " )
868+ throw LoopError . missingDataError ( . reservoir )
867869 }
868870
869871 let startDate = Date ( )
@@ -880,17 +882,17 @@ extension LoopDataManager {
880882
881883 guard glucoseMomentumEffect != nil else {
882884 self . predictedGlucose = nil
883- throw LoopError . missingDataError ( details : " Momentum effects " , recovery : nil )
885+ throw LoopError . missingDataError ( . momentumEffect )
884886 }
885887
886888 guard carbEffect != nil else {
887889 self . predictedGlucose = nil
888- throw LoopError . missingDataError ( details : " Carb effects " , recovery : nil )
890+ throw LoopError . missingDataError ( . carbEffect )
889891 }
890892
891893 guard insulinEffect != nil else {
892894 self . predictedGlucose = nil
893- throw LoopError . missingDataError ( details : " Insulin effects " , recovery : nil )
895+ throw LoopError . missingDataError ( . insulinEffect )
894896 }
895897
896898 let predictedGlucose = try predictGlucose ( using: settings. enabledEffects)
@@ -904,7 +906,7 @@ extension LoopDataManager {
904906 let maxBolus = settings. maximumBolus,
905907 let model = insulinModelSettings? . model
906908 else {
907- throw LoopError . configurationError ( " Check settings " )
909+ throw LoopError . configurationError ( . generalSettings )
908910 }
909911
910912 guard lastRequestedBolus == nil
0 commit comments