From d639d6557e1eacb5d70267de6880dc25c9b027d3 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 10 Jul 2017 14:52:14 -0400 Subject: [PATCH 1/2] Add owsFail free function for swift. // FREEBIE --- Signal.xcodeproj/project.pbxproj | 4 +++ .../AttachmentPointerAdapter.swift | 19 +++++-------- Signal/src/ProfileFetcherJob.swift | 6 ++-- .../AttachmentApprovalViewController.swift | 4 +-- ...ExperienceUpgradesPageViewController.swift | 12 +++----- .../ViewControllers/SignalAttachment.swift | 28 +++++++------------ Signal/src/call/CallAudioService.swift | 9 ++---- Signal/src/call/CallService.swift | 27 +++++++++--------- Signal/src/call/NonCallKitCallUIAdaptee.swift | 18 ++++++------ Signal/src/call/OutboundCallInitiator.swift | 3 +- Signal/src/call/PeerConnectionClient.swift | 3 +- .../Speakerbox/CallKitCallUIAdaptee.swift | 5 ++-- .../call/UserInterface/CallUIAdapter.swift | 3 +- .../src/contact/SystemContactsFetcher.swift | 20 +++++-------- .../ExperienceUpgrade.swift | 6 ++-- Signal/src/util/OWSAsserts.swift | 9 ++++++ Signal/src/views/AttachmentPointerView.swift | 5 ++-- Signal/src/views/AudioProgressView.swift | 2 +- 18 files changed, 82 insertions(+), 101 deletions(-) create mode 100644 Signal/src/util/OWSAsserts.swift diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 2e4347b12..77f4d5bf5 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3471B1D91EB7C63600F6AEC8 /* NewNonContactConversationViewController.m */; }; 3472229F1EB22FFE00E53955 /* AddToGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */; }; 348F2EAE1F0D21BC00D4ECE0 /* DeviceSleepManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */; }; + 3495BC901F1400FF00B478F5 /* OWSAsserts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3495BC8F1F1400FF00B478F5 /* OWSAsserts.swift */; }; 3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; }; 3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; }; 34B3F8711E8DF1700035BE1A /* AboutTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8351E8DF1700035BE1A /* AboutTableViewController.m */; }; @@ -416,6 +417,7 @@ 3472229D1EB22FFE00E53955 /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = ""; }; 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = ""; }; 348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = ""; }; + 3495BC8F1F1400FF00B478F5 /* OWSAsserts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSAsserts.swift; sourceTree = ""; }; 3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = ""; }; 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSCountryMetadata.m; sourceTree = ""; }; 3497DBED1ECE2E4700DB2605 /* DomainFrontingCountryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DomainFrontingCountryViewController.h; sourceTree = ""; }; @@ -1340,6 +1342,7 @@ BFB074C619A5611000F2947C /* ObservableValue.m */, 76EB04EE18170B33006006FC /* Operation.h */, 76EB04EF18170B33006006FC /* Operation.m */, + 3495BC8F1F1400FF00B478F5 /* OWSAsserts.swift */, 34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */, 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */, 45CD81F01DC03A22004C9430 /* OWSLogger.h */, @@ -2154,6 +2157,7 @@ 45666EC91D994C0D008FE134 /* OWSGroupAvatarBuilder.m in Sources */, 3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */, 34B3F87C1E8DF1700035BE1A /* FingerprintViewController.m in Sources */, + 3495BC901F1400FF00B478F5 /* OWSAsserts.swift in Sources */, 76EB058218170B33006006FC /* Environment.m in Sources */, 34B3F8921E8DF1710035BE1A /* SignalAttachment.swift in Sources */, 45464DBC1DFA041F001D3FD6 /* DataChannelMessage.swift in Sources */, diff --git a/Signal/src/Models/TSMessageAdapaters/AttachmentPointerAdapter.swift b/Signal/src/Models/TSMessageAdapaters/AttachmentPointerAdapter.swift index 906548e8c..1d115ef96 100644 --- a/Signal/src/Models/TSMessageAdapaters/AttachmentPointerAdapter.swift +++ b/Signal/src/Models/TSMessageAdapaters/AttachmentPointerAdapter.swift @@ -23,7 +23,7 @@ class AttachmentPointerAdapter: JSQMediaItem, OWSMessageEditing { @available(*, unavailable) required init?(coder aDecoder: NSCoder) { - assertionFailure("init(coder:) has not been implemented") + owsFail("init(coder:) has not been implemented") self.isIncoming = true self.attachmentPointer = TSAttachmentPointer() super.init(coder: aDecoder) @@ -36,8 +36,7 @@ class AttachmentPointerAdapter: JSQMediaItem, OWSMessageEditing { func performAction(_ action: Selector) { // Should not get here, as you can't perform any actions on a downloading attachment. - Logger.error("\(TAG) unexpectedly trying to perform action: \(action) on downloading attachment.") - assertionFailure() + owsFail("\(TAG) unexpectedly trying to perform action: \(action) on downloading attachment.") } // MARK: JSQ Overrides @@ -88,30 +87,26 @@ class AttachmentPointerAdapter: JSQMediaItem, OWSMessageEditing { func attachmentDownloadProgress(_ notification: NSNotification) { guard let attachmentPointerView = self.attachmentPointerView else { - Logger.error("\(TAG) downloading view was unexpectedly nil for notification: \(notification)") - assertionFailure() + owsFail("\(TAG) downloading view was unexpectedly nil for notification: \(notification)") return } guard let userInfo = notification.userInfo else { - Logger.error("\(TAG) user info was unexpectedly nil for notification: \(notification)") - assertionFailure() + owsFail("\(TAG) user info was unexpectedly nil for notification: \(notification)") return } guard let progress = userInfo[kAttachmentDownloadProgressKey] as? CGFloat else { - Logger.error("\(TAG) missing progress measure for notification user info: \(userInfo)") - assertionFailure() + owsFail("\(TAG) missing progress measure for notification user info: \(userInfo)") return } guard let attachmentId = userInfo[kAttachmentDownloadAttachmentIDKey] as? String else { - Logger.error("\(TAG) missing attachmentId for notification user info: \(userInfo)") - assertionFailure() + owsFail("\(TAG) missing attachmentId for notification user info: \(userInfo)") return } - if (self.attachmentPointer.uniqueId == attachmentId) { + if self.attachmentPointer.uniqueId == attachmentId { attachmentPointerView.progress = progress } } diff --git a/Signal/src/ProfileFetcherJob.swift b/Signal/src/ProfileFetcherJob.swift index f9011b408..c53a39701 100644 --- a/Signal/src/ProfileFetcherJob.swift +++ b/Signal/src/ProfileFetcherJob.swift @@ -62,8 +62,7 @@ class ProfileFetcherJob: NSObject { request, success: { (_: URLSessionDataTask?, responseObject: Any?) -> Void in guard let profileResponse = SignalServiceProfile(recipientId: recipientId, rawResponse: responseObject) else { - Logger.error("\(self.TAG) response object had unexpected content") - assertionFailure("\(self.TAG) response object had unexpected content") + owsFail("\(self.TAG) response object had unexpected content") return } @@ -71,8 +70,7 @@ class ProfileFetcherJob: NSObject { }, failure: { (_: URLSessionDataTask?, error: Error?) in guard let error = error else { - Logger.error("\(self.TAG) error in \(#function) was surpringly nil. sheesh rough day.") - assertionFailure("\(self.TAG) error in \(#function) was surpringly nil. sheesh rough day.") + owsFail("\(self.TAG) error in \(#function) was surpringly nil. sheesh rough day.") return } diff --git a/Signal/src/ViewControllers/AttachmentApprovalViewController.swift b/Signal/src/ViewControllers/AttachmentApprovalViewController.swift index c619df0af..eb5d6824c 100644 --- a/Signal/src/ViewControllers/AttachmentApprovalViewController.swift +++ b/Signal/src/ViewControllers/AttachmentApprovalViewController.swift @@ -33,7 +33,7 @@ class AttachmentApprovalViewController: UIViewController, OWSAudioAttachmentPlay dataUTI: kUTTypeContent as String, filename:nil) super.init(coder: aDecoder) - assertionFailure() + owsFail("\(self.TAG) invalid constructor") } required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) { @@ -438,7 +438,7 @@ class AttachmentApprovalViewController: UIViewController, OWSAudioAttachmentPlay private func updateAudioStatusLabel() { guard let audioStatusLabel = self.audioStatusLabel else { - assertionFailure("Missing audio status label") + owsFail("Missing audio status label") return } diff --git a/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift b/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift index 33848a53e..f960be65b 100644 --- a/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift +++ b/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift @@ -165,8 +165,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll override func viewDidLoad() { guard let firstViewController = allViewControllers.first else { - Logger.error("\(TAG) no pages to show.") - assertionFailure() + owsFail("\(TAG) no pages to show.") dismiss(animated: true) return } @@ -246,8 +245,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { Logger.debug("\(TAG) in \(#function)") guard let currentIndex = self.viewControllerIndexes[viewController] else { - assertionFailure() - Logger.error("\(TAG) unknown view controller: \(viewController)") + owsFail("\(TAG) unknown view controller: \(viewController)") return nil } @@ -262,8 +260,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { Logger.debug("\(TAG) in \(#function)") guard let currentIndex = self.viewControllerIndexes[viewController] else { - assertionFailure() - Logger.error("\(TAG) unknown view controller: \(viewController)") + owsFail("\(TAG) unknown view controller: \(viewController)") return nil } @@ -296,8 +293,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll public func addViewController(experienceUpgrade: ExperienceUpgrade) { guard let identifier = ExperienceUpgradeId(rawValue: experienceUpgrade.uniqueId) else { - Logger.error("\(TAG) unknown experience upgrade. skipping") - assertionFailure() + owsFail("\(TAG) unknown experience upgrade. skipping") return } diff --git a/Signal/src/ViewControllers/SignalAttachment.swift b/Signal/src/ViewControllers/SignalAttachment.swift index 88b7d7734..787b04944 100644 --- a/Signal/src/ViewControllers/SignalAttachment.swift +++ b/Signal/src/ViewControllers/SignalAttachment.swift @@ -130,8 +130,7 @@ class SignalAttachment: NSObject { do { try data.write(to: fileUrl) } catch { - Logger.error("\(SignalAttachment.TAG) Could not write data to disk: \(dataUTI)") - assertionFailure() + owsFail("\(SignalAttachment.TAG) Could not write data to disk: \(dataUTI)") return nil } temporaryDataUrl = fileUrl @@ -146,7 +145,7 @@ class SignalAttachment: NSObject { var errorName: String? { guard let error = error else { // This method should only be called if there is an error. - assertionFailure() + owsFail("Missing error") return nil } @@ -156,7 +155,7 @@ class SignalAttachment: NSObject { var localizedErrorDescription: String? { guard let error = self.error else { // This method should only be called if there is an error. - assertionFailure() + owsFail("Missing error") return nil } @@ -366,8 +365,7 @@ class SignalAttachment: NSObject { for dataUTI in inputImageUTISet { if pasteboardUTISet.contains(dataUTI) { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } return imageAttachment(data : data, dataUTI : dataUTI, filename: nil) @@ -376,8 +374,7 @@ class SignalAttachment: NSObject { for dataUTI in videoUTISet { if pasteboardUTISet.contains(dataUTI) { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } return videoAttachment(data : data, dataUTI : dataUTI, filename: nil) @@ -386,8 +383,7 @@ class SignalAttachment: NSObject { for dataUTI in audioUTISet { if pasteboardUTISet.contains(dataUTI) { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } return audioAttachment(data : data, dataUTI : dataUTI, filename: nil) @@ -396,8 +392,7 @@ class SignalAttachment: NSObject { let dataUTI = pasteboardUTISet[pasteboardUTISet.startIndex] guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } return genericAttachment(data : data, dataUTI : dataUTI, filename: nil) @@ -408,18 +403,15 @@ class SignalAttachment: NSObject { private class func dataForFirstPasteboardItem(dataUTI: String) -> Data? { let itemSet = IndexSet(integer:0) guard let datas = UIPasteboard.general.data(forPasteboardType:dataUTI, inItemSet:itemSet) else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } guard datas.count > 0 else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } guard let data = datas[0] as? Data else { - Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") - assertionFailure() + owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") return nil } return data diff --git a/Signal/src/call/CallAudioService.swift b/Signal/src/call/CallAudioService.swift index f315d83e7..4ee9ba511 100644 --- a/Signal/src/call/CallAudioService.swift +++ b/Signal/src/call/CallAudioService.swift @@ -42,9 +42,8 @@ import AVFoundation newPlayer?.numberOfLoops = -1 } } catch { - Logger.error("\(self.TAG) faild to build audio player with error: \(error)") + owsFail("\(self.TAG) failed to build audio player with error: \(error)") newPlayer = nil - assertionFailure() } return newPlayer }() @@ -254,8 +253,7 @@ import AVFoundation private func play(sound: Sound) { guard let newPlayer = sound.player else { - Logger.error("\(self.TAG) unable to build player") - assertionFailure() + owsFail("\(self.TAG) unable to build player") return } Logger.info("\(self.TAG) playing sound: \(sound.filePath)") @@ -355,8 +353,7 @@ import AVFoundation } } catch { let message = "\(self.TAG) in \(#function) failed to set category: \(category) mode: \(String(describing: mode)), options: \(options) with error: \(error)" - assertionFailure(message) - Logger.error(message) + owsFail(message) } } } diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index a14f2c19d..6a1bb46fd 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -290,7 +290,7 @@ protocol CallServiceObserver: class { throw CallError.obsoleteCall(description:"obsolete call in \(#function)") } guard let peerConnectionClient = self.peerConnectionClient else { - assertionFailure("Missing peerConnectionClient in \(#function)") + owsFail("Missing peerConnectionClient in \(#function)") throw CallError.obsoleteCall(description:"Missing peerConnectionClient in \(#function)") } @@ -449,8 +449,7 @@ protocol CallServiceObserver: class { switch untrustedIdentity!.verificationState { case .verified: - Logger.error("\(TAG) shouldn't have missed a call due to untrusted identity if the identity is verified") - assertionFailure("shouldn't have missed a call due to untrusted identity if the identity is verified") + owsFail("\(TAG) shouldn't have missed a call due to untrusted identity if the identity is verified") self.notificationsAdapter.presentMissedCall(newCall, callerName: callerName) case .default: self.notificationsAdapter.presentMissedCallBecauseOfNewIdentity(call: newCall, callerName: callerName) @@ -733,14 +732,14 @@ protocol CallServiceObserver: class { guard let call = self.call else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) call was unexpectedly nil in \(#function)") + owsFail("\(TAG) call was unexpectedly nil in \(#function)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call was unexpectedly nil in \(#function)")) return } guard call.localId == localId else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)") + owsFail("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)")) return } @@ -823,14 +822,14 @@ protocol CallServiceObserver: class { guard let call = self.call else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) call was unexpectedly nil in \(#function)") + owsFail("\(TAG) call was unexpectedly nil in \(#function)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call was unexpectedly nil in \(#function)")) return } guard call.localId == localId else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)") + owsFail("\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)")) return } @@ -849,7 +848,7 @@ protocol CallServiceObserver: class { Logger.info("\(TAG) in \(#function): \(call.identifiersForLogs).") if let callRecord = call.callRecord { - assertionFailure("Not expecting callrecord to already be set") + owsFail("Not expecting callrecord to already be set") callRecord.updateCallType(RPRecentCallTypeIncomingDeclined) } else { let callRecord = TSCall(timestamp: NSDate.ows_millisecondTimeStamp(), withCallNumber: call.remotePhoneNumber, callType: RPRecentCallTypeIncomingDeclined, in: call.thread) @@ -919,7 +918,7 @@ protocol CallServiceObserver: class { guard let call = self.call else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) call was unexpectedly nil in \(#function)") + owsFail("\(TAG) call was unexpectedly nil in \(#function)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call unexpectedly nil in \(#function)")) return } @@ -973,7 +972,7 @@ protocol CallServiceObserver: class { guard let call = self.call else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) call was unexpectedly nil in \(#function)") + owsFail("\(TAG) call was unexpectedly nil in \(#function)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call unexpectedly nil in \(#function)")) return } @@ -1011,7 +1010,7 @@ protocol CallServiceObserver: class { guard let call = self.call else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) received data message, but there is no current call. Ignoring.") + owsFail("\(TAG) received data message, but there is no current call. Ignoring.") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) received data message, but there is no current call. Ignoring.")) return } @@ -1023,7 +1022,7 @@ protocol CallServiceObserver: class { guard connected.id == call.signalingId else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)") + owsFail("\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)")) return } @@ -1038,7 +1037,7 @@ protocol CallServiceObserver: class { guard hangup.id == call.signalingId else { // This should never happen; return to a known good state. - assertionFailure("\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)") + owsFail("\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)") handleFailedCurrentCall(error: .assertionError(description:"\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)")) return } @@ -1231,7 +1230,7 @@ protocol CallServiceObserver: class { AssertIsOnMainThread() if case .assertionError(let description) = error { - assertionFailure(description) + owsFail(description) } if let failedCall = failedCall { diff --git a/Signal/src/call/NonCallKitCallUIAdaptee.swift b/Signal/src/call/NonCallKitCallUIAdaptee.swift index 6096dbfd3..2a4861ca0 100644 --- a/Signal/src/call/NonCallKitCallUIAdaptee.swift +++ b/Signal/src/call/NonCallKitCallUIAdaptee.swift @@ -61,12 +61,12 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { AssertIsOnMainThread() guard let call = self.callService.call else { - assertionFailure("\(self.TAG) in \(#function) No current call.") + owsFail("\(self.TAG) in \(#function) No current call.") return } guard call.localId == localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } @@ -77,7 +77,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { AssertIsOnMainThread() guard call.localId == self.callService.call?.localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } @@ -89,12 +89,12 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { AssertIsOnMainThread() guard let call = self.callService.call else { - assertionFailure("\(self.TAG) in \(#function) No current call.") + owsFail("\(self.TAG) in \(#function) No current call.") return } guard call.localId == localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } @@ -105,7 +105,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { AssertIsOnMainThread() guard call.localId == self.callService.call?.localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } @@ -124,7 +124,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { // If both parties hang up at the same moment, // call might already be nil. guard self.callService.call == nil || call.localId == self.callService.call?.localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } @@ -153,7 +153,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { AssertIsOnMainThread() guard call.localId == self.callService.call?.localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } @@ -164,7 +164,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee { AssertIsOnMainThread() guard call.localId == self.callService.call?.localId else { - assertionFailure("\(self.TAG) in \(#function) localId does not match current call") + owsFail("\(self.TAG) in \(#function) localId does not match current call") return } diff --git a/Signal/src/call/OutboundCallInitiator.swift b/Signal/src/call/OutboundCallInitiator.swift index e898e5c33..eb8358815 100644 --- a/Signal/src/call/OutboundCallInitiator.swift +++ b/Signal/src/call/OutboundCallInitiator.swift @@ -41,8 +41,7 @@ import Foundation // Rather than an init-assigned dependency property, we access `callUIAdapter` via Environment // because it can change after app launch due to user settings guard let callUIAdapter = Environment.getCurrent().callUIAdapter else { - assertionFailure() - Logger.error("\(TAG) can't initiate call because callUIAdapter is nil") + owsFail("\(TAG) can't initiate call because callUIAdapter is nil") return false } diff --git a/Signal/src/call/PeerConnectionClient.swift b/Signal/src/call/PeerConnectionClient.swift index 3c76a3d3c..13626bb57 100644 --- a/Signal/src/call/PeerConnectionClient.swift +++ b/Signal/src/call/PeerConnectionClient.swift @@ -227,8 +227,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD return } guard let videoCaptureSession = self.videoCaptureSession else { - Logger.error("\(self.TAG) videoCaptureSession was unexpectedly nil") - assertionFailure() + owsFail("\(self.TAG) videoCaptureSession was unexpectedly nil") return } diff --git a/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift b/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift index 159ebbdbf..b93d1199f 100644 --- a/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift +++ b/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift @@ -132,7 +132,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate { AssertIsOnMainThread() Logger.debug("\(self.TAG) \(#function)") - assertionFailure("CallKit should answer calls via system call screen, not via notifications.") + owsFail("\(self.TAG) \(#function) CallKit should answer calls via system call screen, not via notifications.") } func answerCall(_ call: SignalCall) { @@ -144,9 +144,8 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate { func declineCall(localId: UUID) { AssertIsOnMainThread() - Logger.debug("\(self.TAG) \(#function)") - assertionFailure("CallKit should decline calls via system call screen, not via notifications.") + owsFail("\(self.TAG) \(#function) CallKit should decline calls via system call screen, not via notifications.") } func declineCall(_ call: SignalCall) { diff --git a/Signal/src/call/UserInterface/CallUIAdapter.swift b/Signal/src/call/UserInterface/CallUIAdapter.swift index 32ec07fb3..445d3e5a6 100644 --- a/Signal/src/call/UserInterface/CallUIAdapter.swift +++ b/Signal/src/call/UserInterface/CallUIAdapter.swift @@ -41,8 +41,7 @@ extension CallUIAdaptee { callViewController.modalTransitionStyle = .crossDissolve guard let presentingViewController = Environment.getCurrent().signalsViewController else { - Logger.error("in \(#function) view controller unexpectedly nil") - assertionFailure("in \(#function) view controller unexpectedly nil") + owsFail("in \(#function) view controller unexpectedly nil") return } diff --git a/Signal/src/contact/SystemContactsFetcher.swift b/Signal/src/contact/SystemContactsFetcher.swift index 68449f959..41408e855 100644 --- a/Signal/src/contact/SystemContactsFetcher.swift +++ b/Signal/src/contact/SystemContactsFetcher.swift @@ -76,8 +76,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee { @objc func runChangeHandler() { guard let changeHandler = self.changeHandler else { - Logger.error("\(TAG) trying to run change handler before it was registered") - assertionFailure() + owsFail("\(TAG) trying to run change handler before it was registered") return } changeHandler() @@ -96,8 +95,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee { systemContacts.append(contact) } } catch let error as NSError { - Logger.error("\(self.TAG) Failed to fetch contacts with error:\(error)") - assertionFailure() + owsFail("\(self.TAG) Failed to fetch contacts with error:\(error)") return .error(error) } @@ -134,8 +132,7 @@ class AddressBookContactStoreAdaptee: ContactStoreAdaptee { @objc func runChangeHandler() { guard let changeHandler = self.changeHandler else { - Logger.error("\(TAG) trying to run change handler before it was registered") - assertionFailure() + owsFail("\(TAG) trying to run change handler before it was registered") return } changeHandler() @@ -180,7 +177,7 @@ class AddressBookContactStoreAdaptee: ContactStoreAdaptee { let lastName = addressBookRecord.lastName let phoneNumbers = addressBookRecord.phoneNumbers - if (firstName == nil && lastName == nil) { + if firstName == nil && lastName == nil { if let companyName = addressBookRecord.companyName { firstName = companyName } else { @@ -338,8 +335,7 @@ class SystemContactsFetcher: NSObject { public var isAuthorized: Bool { guard self.authorizationStatus != .notDetermined else { - assertionFailure("should have called `requestOnce` before this point.") - Logger.error("\(TAG) should have called `requestOnce` before checking authorization status.") + owsFail("should have called `requestOnce` before checking authorization status.") return false } @@ -399,9 +395,8 @@ class SystemContactsFetcher: NSObject { } guard granted else { - Logger.info("\(self.TAG) declined contact access.") // This case should have been caught be the error guard a few lines up. - assertionFailure() + owsFail("\(self.TAG) declined contact access.") DispatchQueue.main.async { completion?(nil) } @@ -450,8 +445,7 @@ class SystemContactsFetcher: NSObject { } guard let contacts = fetchedContacts else { - Logger.error("\(self.TAG) contacts was unexpectedly not set.") - assertionFailure() + owsFail("\(self.TAG) contacts was unexpectedly not set.") completion?(nil) } diff --git a/Signal/src/environment/ExperienceUpgrades/ExperienceUpgrade.swift b/Signal/src/environment/ExperienceUpgrades/ExperienceUpgrade.swift index 28117c6ba..1cf694601 100644 --- a/Signal/src/environment/ExperienceUpgrades/ExperienceUpgrade.swift +++ b/Signal/src/environment/ExperienceUpgrades/ExperienceUpgrade.swift @@ -26,7 +26,7 @@ class ExperienceUpgrade: TSYapDatabaseObject { self.image = nil super.init(uniqueId: uniqueId) } - + required init!(coder: NSCoder!) { // This is the unfortunate seam between strict swift and fast-and-loose objc // we can't leave these properties nil, since we really "don't know" that the superclass @@ -36,7 +36,7 @@ class ExperienceUpgrade: TSYapDatabaseObject { self.image = nil super.init(coder: coder) } - + required init(dictionary dictionaryValue: [AnyHashable : Any]!) throws { // This is the unfortunate seam between strict swift and fast-and-loose objc // we can't leave these properties nil, since we really "don't know" that the superclass @@ -57,7 +57,7 @@ class ExperienceUpgrade: TSYapDatabaseObject { return super.storageBehaviorForProperty(withKey: propertyKey) } else { // Being conservative here in case we rename a property. - assertionFailure("unknown property \(propertyKey)") + owsFail("unknown property \(propertyKey)") return super.storageBehaviorForProperty(withKey: propertyKey) } } diff --git a/Signal/src/util/OWSAsserts.swift b/Signal/src/util/OWSAsserts.swift new file mode 100644 index 000000000..7c8b2b8af --- /dev/null +++ b/Signal/src/util/OWSAsserts.swift @@ -0,0 +1,9 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +func owsFail(_ message: String) { + Logger.error(message) + Logger.flush() + owsFail(message) +} diff --git a/Signal/src/views/AttachmentPointerView.swift b/Signal/src/views/AttachmentPointerView.swift index e483f43d4..14366f444 100644 --- a/Signal/src/views/AttachmentPointerView.swift +++ b/Signal/src/views/AttachmentPointerView.swift @@ -41,7 +41,7 @@ class AttachmentPointerView: UIView { @available(*, unavailable) override init(frame: CGRect) { - assertionFailure() + owsFail("invalid constructor") // This initializer should never be called, but we assign some bogus values to keep the compiler happy. self.filename = genericFilename self.isIncoming = false @@ -53,7 +53,8 @@ class AttachmentPointerView: UIView { @available(*, unavailable) required init?(coder aDecoder: NSCoder) { - assertionFailure() + owsFail("Invalid constructor") + // This initializer should never be called, but we assign some bogus values to keep the compiler happy. self.filename = genericFilename self.isIncoming = false diff --git a/Signal/src/views/AudioProgressView.swift b/Signal/src/views/AudioProgressView.swift index 1f2fc76d1..1aef8f365 100644 --- a/Signal/src/views/AudioProgressView.swift +++ b/Signal/src/views/AudioProgressView.swift @@ -52,7 +52,7 @@ import UIKit super.init(coder: aDecoder) - assertionFailure() + owsFail("\(self.tag) Invalid constructor") } public required init() { From c9355630c789ab899489bf08a408cbe338249cfe Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 11 Jul 2017 16:21:17 -0400 Subject: [PATCH 2/2] Respond to CR. // FREEBIE --- Signal/src/util/OWSAsserts.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/src/util/OWSAsserts.swift b/Signal/src/util/OWSAsserts.swift index 7c8b2b8af..b9313d919 100644 --- a/Signal/src/util/OWSAsserts.swift +++ b/Signal/src/util/OWSAsserts.swift @@ -5,5 +5,5 @@ func owsFail(_ message: String) { Logger.error(message) Logger.flush() - owsFail(message) + assertionFailure(message) }