Просмотр исходного кода

Merge pull request #725 from kingst/fix-error-message-not-enough-readings

Improve error messaging for invalid glucose
Deniz Cengiz 9 месяцев назад
Родитель
Сommit
128a23abfa

+ 17 - 3
Trio/Sources/APS/APSManager.swift

@@ -423,20 +423,26 @@ final class BaseAPSManager: APSManager, Injectable {
         // Fetch glucose asynchronously
         let glucose = try await fetchGlucose(predicate: NSPredicate.predicateForOneHourAgo, fetchLimit: 6)
 
+        var invalidGlucoseError: String?
+
         // Perform the context-related checks and actions
         let isValidGlucoseData = await privateContext.perform { [weak self] in
             guard let self else { return false }
 
             guard glucose.count > 2 else {
                 debug(.apsManager, "Not enough glucose data")
-                self.processError(APSError.glucoseError(message: String(localized: "Not enough glucose data")))
+                invalidGlucoseError =
+                    String(
+                        localized: "Not enough glucose data. You need at least three glucose readings in the last six hours to run the algorithm."
+                    )
                 return false
             }
 
             let dateOfLastGlucose = glucose.first?.date
             guard dateOfLastGlucose ?? Date() >= Date().addingTimeInterval(-12.minutes.timeInterval) else {
                 debug(.apsManager, "Glucose data is stale")
-                self.processError(APSError.glucoseError(message: String(localized: "Glucose data is stale")))
+                invalidGlucoseError =
+                    String(localized: "Glucose data is stale. The most recent glucose reading is from more than 12 minutes ago.")
                 return false
             }
 
@@ -468,7 +474,15 @@ final class BaseAPSManager: APSManager, Injectable {
                 }
             }
         } catch {
-            throw APSError.apsError(message: "Error determining basal: \(error.localizedDescription)")
+            // if we have a glucose validation error we might still run
+            // determineBasal to try to get IoB and CoB updates but we
+            // know that it will fail, so the invalidGlucoseError always
+            // takes priority
+            if let invalidGlucoseError = invalidGlucoseError {
+                throw APSError.apsError(message: invalidGlucoseError)
+            } else {
+                throw APSError.apsError(message: "Error determining basal: \(error.localizedDescription)")
+            }
         }
     }
 

+ 8 - 0
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -104882,6 +104882,7 @@
       }
     },
     "Glucose data is stale" : {
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -104987,6 +104988,9 @@
         }
       }
     },
+    "Glucose data is stale. The most recent glucose reading is from more than 12 minutes ago." : {
+
+    },
     "Glucose data is too flat" : {
       "extractionState" : "stale",
       "localizations" : {
@@ -149671,6 +149675,7 @@
       }
     },
     "Not enough glucose data" : {
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -149776,6 +149781,9 @@
         }
       }
     },
+    "Not enough glucose data. You need at least three glucose readings in the last six hours to run the algorithm." : {
+
+    },
     "Not looping." : {
       "localizations" : {
         "bg" : {