From 80e4ffc11dabd7c209e89d426c147a696d7ff545 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Tue, 25 Jun 2019 10:29:31 -0700 Subject: [PATCH] Use LocalizedError and not Error in swift, and override errorDescription --- .../ios/FxAClient/Errors/FxAError.swift | 16 ++++++++- .../ios/Logins/Errors/LoginStoreError.swift | 26 +++++++++++++- .../ios/Places/Errors/PlacesError.swift | 34 ++++++++++++++++++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/components/fxa-client/ios/FxAClient/Errors/FxAError.swift b/components/fxa-client/ios/FxAClient/Errors/FxAError.swift index ed4fc3f6d..4af66ec79 100644 --- a/components/fxa-client/ios/FxAClient/Errors/FxAError.swift +++ b/components/fxa-client/ios/FxAClient/Errors/FxAError.swift @@ -7,12 +7,26 @@ import Foundation // FIXME: these should be lower case. // swiftlint:disable identifier_name -public enum FirefoxAccountError: Error { +public enum FirefoxAccountError: LocalizedError { case Unauthorized(message: String) case Network(message: String) case Unspecified(message: String) case Panic(message: String) + /// Our implementation of the localizedError protocol -- (This shows up in Sentry) + public var errorDescription: String? { + switch self { + case let .Unauthorized(message): + return "FirefoxAccountError.Unauthorized: \(message)" + case let .Network(message): + return "FirefoxAccountError.Network: \(message)" + case let .Unspecified(message): + return "FirefoxAccountError.Unspecified: \(message)" + case let .Panic(message): + return "FirefoxAccountError.Panic: \(message)" + } + } + // The name is attempting to indicate that we free fxaError.message if it // existed, and that it's a very bad idea to touch it after you call this // function diff --git a/components/logins/ios/Logins/Errors/LoginStoreError.swift b/components/logins/ios/Logins/Errors/LoginStoreError.swift index a888065cf..af163ee6c 100644 --- a/components/logins/ios/Logins/Errors/LoginStoreError.swift +++ b/components/logins/ios/Logins/Errors/LoginStoreError.swift @@ -5,7 +5,7 @@ import Foundation /// Indicates an error occurred while calling into the logins storage layer -public enum LoginsStoreError: Error { +public enum LoginsStoreError: LocalizedError { /// This is a catch-all error code used for errors not yet exposed to consumers, /// typically since it doesn't seem like there's a sane way for them to be handled. case unspecified(message: String) @@ -45,6 +45,30 @@ public enum LoginsStoreError: Error { /// abort some operation. case interrupted(message: String) + /// Our implementation of the localizedError protocol -- (This shows up in Sentry) + public var errorDescription: String? { + switch self { + case let .unspecified(message): + return "LoginsStoreError.unspecified: \(message)" + case let .panic(message): + return "LoginsStoreError.panic: \(message)" + case let .authInvalid(message): + return "LoginsStoreError.authInvalid: \(message)" + case let .noSuchRecord(message): + return "LoginsStoreError.noSuchRecord: \(message)" + case let .duplicateGuid(message): + return "LoginsStoreError.duplicateGuid: \(message)" + case let .invalidLogin(message): + return "LoginsStoreError.invalidLogin: \(message)" + case let .invalidKey(message): + return "LoginsStoreError.invalidKey: \(message)" + case let .network(message): + return "LoginsStoreError.network: \(message)" + case let .interrupted(message): + return "LoginsStoreError.interrupted: \(message)" + } + } + // The name is attempting to indicate that we free rustError.message if it // existed, and that it's a very bad idea to touch it after you call this // function diff --git a/components/places/ios/Places/Errors/PlacesError.swift b/components/places/ios/Places/Errors/PlacesError.swift index d9f5dd0c1..c491dece4 100644 --- a/components/places/ios/Places/Errors/PlacesError.swift +++ b/components/places/ios/Places/Errors/PlacesError.swift @@ -6,7 +6,7 @@ import Foundation import os.log /// Indicates an error occurred while calling into the places storage layer -public enum PlacesError: Error { +public enum PlacesError: LocalizedError { /// This indicates an attempt to use a connection after the PlacesAPI /// it came from is destroyed. This indicates a usage error of this library. case connUseAfterAPIClosed @@ -56,6 +56,38 @@ public enum PlacesError: Error { /// insert a new item as a child of root________. case cannotUpdateRoot(message: String) + /// Our implementation of the localizedError protocol -- (This shows up in Sentry) + public var errorDescription: String? { + switch self { + case .connUseAfterAPIClosed: + return "PlacesError.connUseAfterAPIClosed" + case let .unexpected(message): + return "PlacesError.unexpected: \(message)" + case let .panic(message): + return "PlacesError.panic: \(message)" + case let .invalidPlace(message): + return "PlacesError.invalidPlace: \(message)" + case let .urlParseError(message): + return "PlacesError.urlParseError: \(message)" + case let .databaseBusy(message): + return "PlacesError.databaseBusy: \(message)" + case let .databaseInterrupted(message): + return "PlacesError.databaseInterrupted: \(message)" + case let .databaseCorrupt(message): + return "PlacesError.databaseCorrupt: \(message)" + case let .invalidParent(message): + return "PlacesError.invalidParent: \(message)" + case let .noSuchItem(message): + return "PlacesError.noSuchItem: \(message)" + case let .urlTooLong(message): + return "PlacesError.urlTooLong: \(message)" + case let .illegalChange(message): + return "PlacesError.illegalChange: \(message)" + case let .cannotUpdateRoot(message): + return "PlacesError.cannotUpdateRoot: \(message)" + } + } + // The name is attempting to indicate that we free rustError.message if it // existed, and that it's a very bad idea to touch it after you call this // function