Browse Source

Add additional ACKs around possible failures

Deniz Cengiz 1 year ago
parent
commit
15843609b1

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

@@ -514,7 +514,10 @@ final class BaseAPSManager: APSManager, Injectable {
             return
         }
 
-        guard let pump = pumpManager else { return }
+        guard let pump = pumpManager else {
+            callback?(false, String(localized: "Error! Failed to enact bolus.", comment: "Error message for enacting a bolus"))
+            return
+        }
 
         let roundedAmount = pump.roundToSupportedBolusVolume(units: amount)
 
@@ -542,7 +545,7 @@ final class BaseAPSManager: APSManager, Injectable {
             }
             callback?(
                 false,
-                String(localized: "Error! Failed to enact bolus.", comment: "Error message for failing to enact a bolus")
+                String(localized: "Error! Bolus failed with error: \(error.localizedDescription)")
             )
         }
     }
@@ -559,7 +562,10 @@ final class BaseAPSManager: APSManager, Injectable {
             processError(APSError.pumpError(error))
             callback?(
                 false,
-                String(localized: "Error! Bolus cancellation failed.", comment: "Error message for canceling a bolus")
+                String(
+                    localized: "Error! Bolus cancellation failed with error: \(error.localizedDescription)",
+                    comment: "Error message for canceling a bolus"
+                )
             )
         }
         bolusReporter?.removeObserver(self)

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

@@ -94783,8 +94783,12 @@
         }
       }
     },
+    "Error! Bolus cancellation failed with error: %@" : {
+      "comment" : "Error message for canceling a bolus"
+    },
     "Error! Bolus cancellation failed." : {
       "comment" : "Error message for canceling a bolus",
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -94884,8 +94888,11 @@
         }
       }
     },
+    "Error! Bolus failed with error: %@" : {
+
+    },
     "Error! Failed to enact bolus." : {
-      "comment" : "Error message for enacting a bolus\nError message for failing to enact a bolus",
+      "comment" : "Error message for enacting a bolus",
       "localizations" : {
         "bg" : {
           "stringUnit" : {

+ 60 - 6
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -560,6 +560,12 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                 self?.handleCombinedRequest(bolusAmount: Decimal(bolusAmount), carbsAmount: Decimal(carbsAmount), date: date)
             } else {
                 debug(.watchManager, "📱 Invalid or incomplete data received from watch. Received:  \(message)")
+                // Acknowledge failure
+                self?.sendAcknowledgment(
+                    toWatch: false,
+                    message: "Error! Invalid or incomplete data received from watch.",
+                    ackCode: .genericFailure
+                )
             }
 
             if message[WatchMessageKeys.cancelOverride] as? Bool == true {
@@ -675,7 +681,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                 carbEntry.isUploadedToNS = false
 
                 do {
-                    guard context.hasChanges else { return }
+                    guard context.hasChanges else {
+                        // Acknowledge failure
+                        self.sendAcknowledgment(
+                            toWatch: false,
+                            message: "Error! Something went wrong when processing your request.",
+                            ackCode: .genericFailure
+                        )
+                        return
+                    }
                     try context.save()
                     debug(.watchManager, "📱 Saved carbs from watch: \(amount)g at \(date)")
 
@@ -725,7 +739,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                     carbEntry.isFPU = false // set this to false to ensure watch-entered carbs are displayed in main chart
                     carbEntry.isUploadedToNS = false
 
-                    guard context.hasChanges else { return }
+                    guard context.hasChanges else {
+                        // Acknowledge failure
+                        self.sendAcknowledgment(
+                            toWatch: false,
+                            message: "Error! Something went wrong when processing your request.",
+                            ackCode: .genericFailure
+                        )
+                        return
+                    }
                     try context.save()
                     debug(.watchManager, "📱 Saved carbs from watch: \(carbsAmount) g at \(date)")
                 }
@@ -782,7 +804,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                         activeOverride.enabled = false
 
                         do {
-                            guard context.hasChanges else { return }
+                            guard context.hasChanges else {
+                                // Acknowledge failure
+                                self.sendAcknowledgment(
+                                    toWatch: false,
+                                    message: "Error! Something went wrong when processing your request.",
+                                    ackCode: .genericFailure
+                                )
+                                return
+                            }
                             try context.save()
                             debug(.watchManager, "📱 Successfully stopped override")
 
@@ -874,7 +904,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                 presetToActivate.date = Date()
 
                 do {
-                    guard context.hasChanges else { return }
+                    guard context.hasChanges else {
+                        // Acknowledge failure
+                        self.sendAcknowledgment(
+                            toWatch: false,
+                            message: "Error! Something went wrong when processing your request.",
+                            ackCode: .genericFailure
+                        )
+                        return
+                    }
                     try context.save()
                     debug(.watchManager, "📱 Successfully activated override: \(presetName)")
 
@@ -933,7 +971,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                     presetToActivate.date = Date()
 
                     do {
-                        guard context.hasChanges else { return }
+                        guard context.hasChanges else {
+                            // Acknowledge failure
+                            self.sendAcknowledgment(
+                                toWatch: false,
+                                message: "Error! Something went wrong when processing your request.",
+                                ackCode: .genericFailure
+                            )
+                            return
+                        }
                         try context.save()
                         debug(.watchManager, "📱 Successfully activated temp target: \(presetName)")
 
@@ -998,7 +1044,15 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                         activeTempTarget.enabled = false
 
                         do {
-                            guard context.hasChanges else { return }
+                            guard context.hasChanges else {
+                                // Acknowledge failure
+                                self.sendAcknowledgment(
+                                    toWatch: false,
+                                    message: "Error! Something went wrong when processing your request.",
+                                    ackCode: .genericFailure
+                                )
+                                return
+                            }
                             try context.save()
                             debug(.watchManager, "📱 Successfully cancelled temp target")