diff --git a/BrowserKit/Sources/Common/Logger/CrashManager.swift b/BrowserKit/Sources/Common/Logger/CrashManager.swift index f49fd9895623..68b14fdc26de 100644 --- a/BrowserKit/Sources/Common/Logger/CrashManager.swift +++ b/BrowserKit/Sources/Common/Logger/CrashManager.swift @@ -73,6 +73,7 @@ public class DefaultCrashManager: CrashManager { private var sentryWrapper: SentryWrapper private var isSimulator: Bool private var skipReleaseNameCheck: Bool + private let logger: Logger // Only enable app hang tracking in Beta for now private var shouldEnableAppHangTracking: Bool { @@ -90,11 +91,13 @@ public class DefaultCrashManager: CrashManager { public init(appInfo: BrowserKitInformation = BrowserKitInformation.shared, sentryWrapper: SentryWrapper = DefaultSentry(), isSimulator: Bool = DeviceInfo.isSimulator(), - skipReleaseNameCheck: Bool = false) { + skipReleaseNameCheck: Bool = false, + logger: Logger = DefaultLogger.shared) { self.appInfo = appInfo self.sentryWrapper = sentryWrapper self.isSimulator = isSimulator self.skipReleaseNameCheck = skipReleaseNameCheck + self.logger = logger } // MARK: - CrashManager protocol @@ -128,8 +131,12 @@ public class DefaultCrashManager: CrashManager { // Turn Sentry breadcrumbs off since we have our own log swizzling options.enableAutoBreadcrumbTracking = false options.beforeSend = { event in - if event.error.self is CustomCrashReport { - self.alterEventForCustomCrash(event: event, crash: event.error as! CustomCrashReport) + if let crashReport = event.error.self as? CustomCrashReport { + self.alterEventForCustomCrash(event: event, crash: crashReport) + } else { + self.logger.log("Encountered an error that is not a CustomCrashReport: \(String(describing: event.error))", + level: .fatal, + category: .lifecycle) } return event } diff --git a/firefox-ios/Client/Helpers/MenuBuilderHelper.swift b/firefox-ios/Client/Helpers/MenuBuilderHelper.swift index 9fbc9e9bed98..6c4897c76add 100644 --- a/firefox-ios/Client/Helpers/MenuBuilderHelper.swift +++ b/firefox-ios/Client/Helpers/MenuBuilderHelper.swift @@ -2,10 +2,17 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/ +import Common import UIKit import Shared class MenuBuilderHelper { + private let logger: Logger + + init(logger: Logger = DefaultLogger.shared) { + self.logger = logger + } + struct MenuIdentifiers { static let history = UIMenu.Identifier("com.mozilla.firefox.menus.history") static let bookmarks = UIMenu.Identifier("com.mozilla.firefox.menus.bookmarks") @@ -67,7 +74,13 @@ class MenuBuilderHelper { ] ) fileMenu.children.forEach { - ($0 as! UIKeyCommand).wantsPriorityOverSystemBehavior = true + guard let fileMenuKeyCommand = $0 as? UIKeyCommand else { + logger.log("Failed to cast file menu child to UIKeyCommand in MenuBuilderHelper class", + level: .fatal, + category: .library) + return + } + fileMenuKeyCommand.wantsPriorityOverSystemBehavior = true } let findMenu = UIMenu( @@ -90,7 +103,13 @@ class MenuBuilderHelper { ] ) findMenu.children.forEach { - ($0 as! UIKeyCommand).wantsPriorityOverSystemBehavior = true + guard let findMenuKeyCommand = $0 as? UIKeyCommand else { + logger.log("Failed to cast find menu child to UIKeyCommand in MenuBuilderHelper class", + level: .fatal, + category: .library) + return + } + findMenuKeyCommand.wantsPriorityOverSystemBehavior = true } var viewMenuChildren: [UIMenuElement] = [ @@ -137,7 +156,13 @@ class MenuBuilderHelper { let viewMenu = UIMenu(options: .displayInline, children: viewMenuChildren) viewMenu.children.forEach { - ($0 as! UIKeyCommand).wantsPriorityOverSystemBehavior = true + guard let viewMenuKeyCommand = $0 as? UIKeyCommand else { + logger.log("Failed to cast view menu child to UIKeyCommand in MenuBuilderHelper class", + level: .fatal, + category: .library) + return + } + viewMenuKeyCommand.wantsPriorityOverSystemBehavior = true } let historyMenu = UIMenu( @@ -255,7 +280,13 @@ class MenuBuilderHelper { if #available(iOS 15, *) { windowMenu.children.forEach { - ($0 as! UIKeyCommand).wantsPriorityOverSystemBehavior = true + guard let windowMenuKeyCommand = $0 as? UIKeyCommand else { + logger.log("Failed to cast window menu child to UIKeyCommand in MenuBuilderHelper class", + level: .fatal, + category: .library) + return + } + windowMenuKeyCommand.wantsPriorityOverSystemBehavior = true } }