Merge branch 'charlesmchen/owsFailSwift'

pull/1/head
Matthew Chen 7 years ago
commit fa09ce08f2

@ -35,6 +35,7 @@
3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3471B1D91EB7C63600F6AEC8 /* NewNonContactConversationViewController.m */; }; 3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3471B1D91EB7C63600F6AEC8 /* NewNonContactConversationViewController.m */; };
3472229F1EB22FFE00E53955 /* AddToGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */; }; 3472229F1EB22FFE00E53955 /* AddToGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */; };
348F2EAE1F0D21BC00D4ECE0 /* DeviceSleepManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */; }; 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 */; }; 3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; };
3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; }; 3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; };
34B3F8711E8DF1700035BE1A /* AboutTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8351E8DF1700035BE1A /* AboutTableViewController.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 = "<group>"; }; 3472229D1EB22FFE00E53955 /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = "<group>"; };
3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = "<group>"; }; 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = "<group>"; };
348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = "<group>"; }; 348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = "<group>"; };
3495BC8F1F1400FF00B478F5 /* OWSAsserts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSAsserts.swift; sourceTree = "<group>"; };
3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = "<group>"; }; 3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = "<group>"; };
3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSCountryMetadata.m; sourceTree = "<group>"; }; 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSCountryMetadata.m; sourceTree = "<group>"; };
3497DBED1ECE2E4700DB2605 /* DomainFrontingCountryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DomainFrontingCountryViewController.h; sourceTree = "<group>"; }; 3497DBED1ECE2E4700DB2605 /* DomainFrontingCountryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DomainFrontingCountryViewController.h; sourceTree = "<group>"; };
@ -1340,6 +1342,7 @@
BFB074C619A5611000F2947C /* ObservableValue.m */, BFB074C619A5611000F2947C /* ObservableValue.m */,
76EB04EE18170B33006006FC /* Operation.h */, 76EB04EE18170B33006006FC /* Operation.h */,
76EB04EF18170B33006006FC /* Operation.m */, 76EB04EF18170B33006006FC /* Operation.m */,
3495BC8F1F1400FF00B478F5 /* OWSAsserts.swift */,
34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */, 34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */,
34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */, 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */,
45CD81F01DC03A22004C9430 /* OWSLogger.h */, 45CD81F01DC03A22004C9430 /* OWSLogger.h */,
@ -2154,6 +2157,7 @@
45666EC91D994C0D008FE134 /* OWSGroupAvatarBuilder.m in Sources */, 45666EC91D994C0D008FE134 /* OWSGroupAvatarBuilder.m in Sources */,
3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */, 3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */,
34B3F87C1E8DF1700035BE1A /* FingerprintViewController.m in Sources */, 34B3F87C1E8DF1700035BE1A /* FingerprintViewController.m in Sources */,
3495BC901F1400FF00B478F5 /* OWSAsserts.swift in Sources */,
76EB058218170B33006006FC /* Environment.m in Sources */, 76EB058218170B33006006FC /* Environment.m in Sources */,
34B3F8921E8DF1710035BE1A /* SignalAttachment.swift in Sources */, 34B3F8921E8DF1710035BE1A /* SignalAttachment.swift in Sources */,
45464DBC1DFA041F001D3FD6 /* DataChannelMessage.swift in Sources */, 45464DBC1DFA041F001D3FD6 /* DataChannelMessage.swift in Sources */,

@ -23,7 +23,7 @@ class AttachmentPointerAdapter: JSQMediaItem, OWSMessageEditing {
@available(*, unavailable) @available(*, unavailable)
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
assertionFailure("init(coder:) has not been implemented") owsFail("init(coder:) has not been implemented")
self.isIncoming = true self.isIncoming = true
self.attachmentPointer = TSAttachmentPointer() self.attachmentPointer = TSAttachmentPointer()
super.init(coder: aDecoder) super.init(coder: aDecoder)
@ -36,8 +36,7 @@ class AttachmentPointerAdapter: JSQMediaItem, OWSMessageEditing {
func performAction(_ action: Selector) { func performAction(_ action: Selector) {
// Should not get here, as you can't perform any actions on a downloading attachment. // 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.") owsFail("\(TAG) unexpectedly trying to perform action: \(action) on downloading attachment.")
assertionFailure()
} }
// MARK: JSQ Overrides // MARK: JSQ Overrides
@ -88,30 +87,26 @@ class AttachmentPointerAdapter: JSQMediaItem, OWSMessageEditing {
func attachmentDownloadProgress(_ notification: NSNotification) { func attachmentDownloadProgress(_ notification: NSNotification) {
guard let attachmentPointerView = self.attachmentPointerView else { guard let attachmentPointerView = self.attachmentPointerView else {
Logger.error("\(TAG) downloading view was unexpectedly nil for notification: \(notification)") owsFail("\(TAG) downloading view was unexpectedly nil for notification: \(notification)")
assertionFailure()
return return
} }
guard let userInfo = notification.userInfo else { guard let userInfo = notification.userInfo else {
Logger.error("\(TAG) user info was unexpectedly nil for notification: \(notification)") owsFail("\(TAG) user info was unexpectedly nil for notification: \(notification)")
assertionFailure()
return return
} }
guard let progress = userInfo[kAttachmentDownloadProgressKey] as? CGFloat else { guard let progress = userInfo[kAttachmentDownloadProgressKey] as? CGFloat else {
Logger.error("\(TAG) missing progress measure for notification user info: \(userInfo)") owsFail("\(TAG) missing progress measure for notification user info: \(userInfo)")
assertionFailure()
return return
} }
guard let attachmentId = userInfo[kAttachmentDownloadAttachmentIDKey] as? String else { guard let attachmentId = userInfo[kAttachmentDownloadAttachmentIDKey] as? String else {
Logger.error("\(TAG) missing attachmentId for notification user info: \(userInfo)") owsFail("\(TAG) missing attachmentId for notification user info: \(userInfo)")
assertionFailure()
return return
} }
if (self.attachmentPointer.uniqueId == attachmentId) { if self.attachmentPointer.uniqueId == attachmentId {
attachmentPointerView.progress = progress attachmentPointerView.progress = progress
} }
} }

@ -62,8 +62,7 @@ class ProfileFetcherJob: NSObject {
request, request,
success: { (_: URLSessionDataTask?, responseObject: Any?) -> Void in success: { (_: URLSessionDataTask?, responseObject: Any?) -> Void in
guard let profileResponse = SignalServiceProfile(recipientId: recipientId, rawResponse: responseObject) else { guard let profileResponse = SignalServiceProfile(recipientId: recipientId, rawResponse: responseObject) else {
Logger.error("\(self.TAG) response object had unexpected content") owsFail("\(self.TAG) response object had unexpected content")
assertionFailure("\(self.TAG) response object had unexpected content")
return return
} }
@ -71,8 +70,7 @@ class ProfileFetcherJob: NSObject {
}, },
failure: { (_: URLSessionDataTask?, error: Error?) in failure: { (_: URLSessionDataTask?, error: Error?) in
guard let error = error else { guard let error = error else {
Logger.error("\(self.TAG) error in \(#function) was surpringly nil. sheesh rough day.") owsFail("\(self.TAG) error in \(#function) was surpringly nil. sheesh rough day.")
assertionFailure("\(self.TAG) error in \(#function) was surpringly nil. sheesh rough day.")
return return
} }

@ -33,7 +33,7 @@ class AttachmentApprovalViewController: UIViewController, OWSAudioAttachmentPlay
dataUTI: kUTTypeContent as String, dataUTI: kUTTypeContent as String,
filename:nil) filename:nil)
super.init(coder: aDecoder) super.init(coder: aDecoder)
assertionFailure() owsFail("\(self.TAG) invalid constructor")
} }
required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) { required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) {
@ -438,7 +438,7 @@ class AttachmentApprovalViewController: UIViewController, OWSAudioAttachmentPlay
private func updateAudioStatusLabel() { private func updateAudioStatusLabel() {
guard let audioStatusLabel = self.audioStatusLabel else { guard let audioStatusLabel = self.audioStatusLabel else {
assertionFailure("Missing audio status label") owsFail("Missing audio status label")
return return
} }

@ -165,8 +165,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll
override func viewDidLoad() { override func viewDidLoad() {
guard let firstViewController = allViewControllers.first else { guard let firstViewController = allViewControllers.first else {
Logger.error("\(TAG) no pages to show.") owsFail("\(TAG) no pages to show.")
assertionFailure()
dismiss(animated: true) dismiss(animated: true)
return return
} }
@ -246,8 +245,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
Logger.debug("\(TAG) in \(#function)") Logger.debug("\(TAG) in \(#function)")
guard let currentIndex = self.viewControllerIndexes[viewController] else { guard let currentIndex = self.viewControllerIndexes[viewController] else {
assertionFailure() owsFail("\(TAG) unknown view controller: \(viewController)")
Logger.error("\(TAG) unknown view controller: \(viewController)")
return nil return nil
} }
@ -262,8 +260,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
Logger.debug("\(TAG) in \(#function)") Logger.debug("\(TAG) in \(#function)")
guard let currentIndex = self.viewControllerIndexes[viewController] else { guard let currentIndex = self.viewControllerIndexes[viewController] else {
assertionFailure() owsFail("\(TAG) unknown view controller: \(viewController)")
Logger.error("\(TAG) unknown view controller: \(viewController)")
return nil return nil
} }
@ -296,8 +293,7 @@ class ExperienceUpgradesPageViewController: UIViewController, UIPageViewControll
public func addViewController(experienceUpgrade: ExperienceUpgrade) { public func addViewController(experienceUpgrade: ExperienceUpgrade) {
guard let identifier = ExperienceUpgradeId(rawValue: experienceUpgrade.uniqueId) else { guard let identifier = ExperienceUpgradeId(rawValue: experienceUpgrade.uniqueId) else {
Logger.error("\(TAG) unknown experience upgrade. skipping") owsFail("\(TAG) unknown experience upgrade. skipping")
assertionFailure()
return return
} }

@ -130,8 +130,7 @@ class SignalAttachment: NSObject {
do { do {
try data.write(to: fileUrl) try data.write(to: fileUrl)
} catch { } catch {
Logger.error("\(SignalAttachment.TAG) Could not write data to disk: \(dataUTI)") owsFail("\(SignalAttachment.TAG) Could not write data to disk: \(dataUTI)")
assertionFailure()
return nil return nil
} }
temporaryDataUrl = fileUrl temporaryDataUrl = fileUrl
@ -146,7 +145,7 @@ class SignalAttachment: NSObject {
var errorName: String? { var errorName: String? {
guard let error = error else { guard let error = error else {
// This method should only be called if there is an error. // This method should only be called if there is an error.
assertionFailure() owsFail("Missing error")
return nil return nil
} }
@ -156,7 +155,7 @@ class SignalAttachment: NSObject {
var localizedErrorDescription: String? { var localizedErrorDescription: String? {
guard let error = self.error else { guard let error = self.error else {
// This method should only be called if there is an error. // This method should only be called if there is an error.
assertionFailure() owsFail("Missing error")
return nil return nil
} }
@ -366,8 +365,7 @@ class SignalAttachment: NSObject {
for dataUTI in inputImageUTISet { for dataUTI in inputImageUTISet {
if pasteboardUTISet.contains(dataUTI) { if pasteboardUTISet.contains(dataUTI) {
guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
return imageAttachment(data : data, dataUTI : dataUTI, filename: nil) return imageAttachment(data : data, dataUTI : dataUTI, filename: nil)
@ -376,8 +374,7 @@ class SignalAttachment: NSObject {
for dataUTI in videoUTISet { for dataUTI in videoUTISet {
if pasteboardUTISet.contains(dataUTI) { if pasteboardUTISet.contains(dataUTI) {
guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
return videoAttachment(data : data, dataUTI : dataUTI, filename: nil) return videoAttachment(data : data, dataUTI : dataUTI, filename: nil)
@ -386,8 +383,7 @@ class SignalAttachment: NSObject {
for dataUTI in audioUTISet { for dataUTI in audioUTISet {
if pasteboardUTISet.contains(dataUTI) { if pasteboardUTISet.contains(dataUTI) {
guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
return audioAttachment(data : data, dataUTI : dataUTI, filename: nil) return audioAttachment(data : data, dataUTI : dataUTI, filename: nil)
@ -396,8 +392,7 @@ class SignalAttachment: NSObject {
let dataUTI = pasteboardUTISet[pasteboardUTISet.startIndex] let dataUTI = pasteboardUTISet[pasteboardUTISet.startIndex]
guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else { guard let data = dataForFirstPasteboardItem(dataUTI:dataUTI) else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
return genericAttachment(data : data, dataUTI : dataUTI, filename: nil) return genericAttachment(data : data, dataUTI : dataUTI, filename: nil)
@ -408,18 +403,15 @@ class SignalAttachment: NSObject {
private class func dataForFirstPasteboardItem(dataUTI: String) -> Data? { private class func dataForFirstPasteboardItem(dataUTI: String) -> Data? {
let itemSet = IndexSet(integer:0) let itemSet = IndexSet(integer:0)
guard let datas = UIPasteboard.general.data(forPasteboardType:dataUTI, inItemSet:itemSet) else { guard let datas = UIPasteboard.general.data(forPasteboardType:dataUTI, inItemSet:itemSet) else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
guard datas.count > 0 else { guard datas.count > 0 else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
guard let data = datas[0] as? Data else { guard let data = datas[0] as? Data else {
Logger.error("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)") owsFail("\(TAG) Missing expected pasteboard data for UTI: \(dataUTI)")
assertionFailure()
return nil return nil
} }
return data return data

@ -42,9 +42,8 @@ import AVFoundation
newPlayer?.numberOfLoops = -1 newPlayer?.numberOfLoops = -1
} }
} catch { } 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 newPlayer = nil
assertionFailure()
} }
return newPlayer return newPlayer
}() }()
@ -254,8 +253,7 @@ import AVFoundation
private func play(sound: Sound) { private func play(sound: Sound) {
guard let newPlayer = sound.player else { guard let newPlayer = sound.player else {
Logger.error("\(self.TAG) unable to build player") owsFail("\(self.TAG) unable to build player")
assertionFailure()
return return
} }
Logger.info("\(self.TAG) playing sound: \(sound.filePath)") Logger.info("\(self.TAG) playing sound: \(sound.filePath)")
@ -355,8 +353,7 @@ import AVFoundation
} }
} catch { } catch {
let message = "\(self.TAG) in \(#function) failed to set category: \(category) mode: \(String(describing: mode)), options: \(options) with error: \(error)" let message = "\(self.TAG) in \(#function) failed to set category: \(category) mode: \(String(describing: mode)), options: \(options) with error: \(error)"
assertionFailure(message) owsFail(message)
Logger.error(message)
} }
} }
} }

@ -290,7 +290,7 @@ protocol CallServiceObserver: class {
throw CallError.obsoleteCall(description:"obsolete call in \(#function)") throw CallError.obsoleteCall(description:"obsolete call in \(#function)")
} }
guard let peerConnectionClient = self.peerConnectionClient else { guard let peerConnectionClient = self.peerConnectionClient else {
assertionFailure("Missing peerConnectionClient in \(#function)") owsFail("Missing peerConnectionClient in \(#function)")
throw CallError.obsoleteCall(description:"Missing peerConnectionClient in \(#function)") throw CallError.obsoleteCall(description:"Missing peerConnectionClient in \(#function)")
} }
@ -449,8 +449,7 @@ protocol CallServiceObserver: class {
switch untrustedIdentity!.verificationState { switch untrustedIdentity!.verificationState {
case .verified: case .verified:
Logger.error("\(TAG) 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")
assertionFailure("shouldn't have missed a call due to untrusted identity if the identity is verified")
self.notificationsAdapter.presentMissedCall(newCall, callerName: callerName) self.notificationsAdapter.presentMissedCall(newCall, callerName: callerName)
case .default: case .default:
self.notificationsAdapter.presentMissedCallBecauseOfNewIdentity(call: newCall, callerName: callerName) self.notificationsAdapter.presentMissedCallBecauseOfNewIdentity(call: newCall, callerName: callerName)
@ -733,14 +732,14 @@ protocol CallServiceObserver: class {
guard let call = self.call else { guard let call = self.call else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call was unexpectedly nil in \(#function)"))
return return
} }
guard call.localId == localId else { guard call.localId == localId else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)"))
return return
} }
@ -823,14 +822,14 @@ protocol CallServiceObserver: class {
guard let call = self.call else { guard let call = self.call else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call was unexpectedly nil in \(#function)"))
return return
} }
guard call.localId == localId else { guard call.localId == localId else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) callLocalId:\(localId) doesn't match current calls: \(call.localId)"))
return return
} }
@ -849,7 +848,7 @@ protocol CallServiceObserver: class {
Logger.info("\(TAG) in \(#function): \(call.identifiersForLogs).") Logger.info("\(TAG) in \(#function): \(call.identifiersForLogs).")
if let callRecord = call.callRecord { if let callRecord = call.callRecord {
assertionFailure("Not expecting callrecord to already be set") owsFail("Not expecting callrecord to already be set")
callRecord.updateCallType(RPRecentCallTypeIncomingDeclined) callRecord.updateCallType(RPRecentCallTypeIncomingDeclined)
} else { } else {
let callRecord = TSCall(timestamp: NSDate.ows_millisecondTimeStamp(), withCallNumber: call.remotePhoneNumber, callType: RPRecentCallTypeIncomingDeclined, in: call.thread) 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 { guard let call = self.call else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call unexpectedly nil in \(#function)"))
return return
} }
@ -973,7 +972,7 @@ protocol CallServiceObserver: class {
guard let call = self.call else { guard let call = self.call else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call unexpectedly nil in \(#function)"))
return return
} }
@ -1011,7 +1010,7 @@ protocol CallServiceObserver: class {
guard let call = self.call else { guard let call = self.call else {
// This should never happen; return to a known good state. // 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.")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) received data message, but there is no current call. Ignoring."))
return return
} }
@ -1023,7 +1022,7 @@ protocol CallServiceObserver: class {
guard connected.id == call.signalingId else { guard connected.id == call.signalingId else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) received connected message for call with id:\(connected.id) but current call has id:\(call.signalingId)"))
return return
} }
@ -1038,7 +1037,7 @@ protocol CallServiceObserver: class {
guard hangup.id == call.signalingId else { guard hangup.id == call.signalingId else {
// This should never happen; return to a known good state. // 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)")) handleFailedCurrentCall(error: .assertionError(description:"\(TAG) received hangup message for call with id:\(hangup.id) but current call has id:\(call.signalingId)"))
return return
} }
@ -1231,7 +1230,7 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread() AssertIsOnMainThread()
if case .assertionError(let description) = error { if case .assertionError(let description) = error {
assertionFailure(description) owsFail(description)
} }
if let failedCall = failedCall { if let failedCall = failedCall {

@ -61,12 +61,12 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
AssertIsOnMainThread() AssertIsOnMainThread()
guard let call = self.callService.call else { guard let call = self.callService.call else {
assertionFailure("\(self.TAG) in \(#function) No current call.") owsFail("\(self.TAG) in \(#function) No current call.")
return return
} }
guard call.localId == localId else { 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 return
} }
@ -77,7 +77,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
AssertIsOnMainThread() AssertIsOnMainThread()
guard call.localId == self.callService.call?.localId else { 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 return
} }
@ -89,12 +89,12 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
AssertIsOnMainThread() AssertIsOnMainThread()
guard let call = self.callService.call else { guard let call = self.callService.call else {
assertionFailure("\(self.TAG) in \(#function) No current call.") owsFail("\(self.TAG) in \(#function) No current call.")
return return
} }
guard call.localId == localId else { 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 return
} }
@ -105,7 +105,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
AssertIsOnMainThread() AssertIsOnMainThread()
guard call.localId == self.callService.call?.localId else { 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 return
} }
@ -124,7 +124,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
// If both parties hang up at the same moment, // If both parties hang up at the same moment,
// call might already be nil. // call might already be nil.
guard self.callService.call == nil || call.localId == self.callService.call?.localId else { 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 return
} }
@ -153,7 +153,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
AssertIsOnMainThread() AssertIsOnMainThread()
guard call.localId == self.callService.call?.localId else { 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 return
} }
@ -164,7 +164,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
AssertIsOnMainThread() AssertIsOnMainThread()
guard call.localId == self.callService.call?.localId else { 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 return
} }

@ -41,8 +41,7 @@ import Foundation
// Rather than an init-assigned dependency property, we access `callUIAdapter` via Environment // Rather than an init-assigned dependency property, we access `callUIAdapter` via Environment
// because it can change after app launch due to user settings // because it can change after app launch due to user settings
guard let callUIAdapter = Environment.getCurrent().callUIAdapter else { guard let callUIAdapter = Environment.getCurrent().callUIAdapter else {
assertionFailure() owsFail("\(TAG) can't initiate call because callUIAdapter is nil")
Logger.error("\(TAG) can't initiate call because callUIAdapter is nil")
return false return false
} }

@ -227,8 +227,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
return return
} }
guard let videoCaptureSession = self.videoCaptureSession else { guard let videoCaptureSession = self.videoCaptureSession else {
Logger.error("\(self.TAG) videoCaptureSession was unexpectedly nil") owsFail("\(self.TAG) videoCaptureSession was unexpectedly nil")
assertionFailure()
return return
} }

@ -132,7 +132,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.debug("\(self.TAG) \(#function)") 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) { func answerCall(_ call: SignalCall) {
@ -144,9 +144,8 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
func declineCall(localId: UUID) { func declineCall(localId: UUID) {
AssertIsOnMainThread() 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) { func declineCall(_ call: SignalCall) {

@ -41,8 +41,7 @@ extension CallUIAdaptee {
callViewController.modalTransitionStyle = .crossDissolve callViewController.modalTransitionStyle = .crossDissolve
guard let presentingViewController = Environment.getCurrent().signalsViewController else { guard let presentingViewController = Environment.getCurrent().signalsViewController else {
Logger.error("in \(#function) view controller unexpectedly nil") owsFail("in \(#function) view controller unexpectedly nil")
assertionFailure("in \(#function) view controller unexpectedly nil")
return return
} }

@ -76,8 +76,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee {
@objc @objc
func runChangeHandler() { func runChangeHandler() {
guard let changeHandler = self.changeHandler else { guard let changeHandler = self.changeHandler else {
Logger.error("\(TAG) trying to run change handler before it was registered") owsFail("\(TAG) trying to run change handler before it was registered")
assertionFailure()
return return
} }
changeHandler() changeHandler()
@ -96,8 +95,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee {
systemContacts.append(contact) systemContacts.append(contact)
} }
} catch let error as NSError { } catch let error as NSError {
Logger.error("\(self.TAG) Failed to fetch contacts with error:\(error)") owsFail("\(self.TAG) Failed to fetch contacts with error:\(error)")
assertionFailure()
return .error(error) return .error(error)
} }
@ -134,8 +132,7 @@ class AddressBookContactStoreAdaptee: ContactStoreAdaptee {
@objc @objc
func runChangeHandler() { func runChangeHandler() {
guard let changeHandler = self.changeHandler else { guard let changeHandler = self.changeHandler else {
Logger.error("\(TAG) trying to run change handler before it was registered") owsFail("\(TAG) trying to run change handler before it was registered")
assertionFailure()
return return
} }
changeHandler() changeHandler()
@ -180,7 +177,7 @@ class AddressBookContactStoreAdaptee: ContactStoreAdaptee {
let lastName = addressBookRecord.lastName let lastName = addressBookRecord.lastName
let phoneNumbers = addressBookRecord.phoneNumbers let phoneNumbers = addressBookRecord.phoneNumbers
if (firstName == nil && lastName == nil) { if firstName == nil && lastName == nil {
if let companyName = addressBookRecord.companyName { if let companyName = addressBookRecord.companyName {
firstName = companyName firstName = companyName
} else { } else {
@ -338,8 +335,7 @@ class SystemContactsFetcher: NSObject {
public var isAuthorized: Bool { public var isAuthorized: Bool {
guard self.authorizationStatus != .notDetermined else { guard self.authorizationStatus != .notDetermined else {
assertionFailure("should have called `requestOnce` before this point.") owsFail("should have called `requestOnce` before checking authorization status.")
Logger.error("\(TAG) should have called `requestOnce` before checking authorization status.")
return false return false
} }
@ -399,9 +395,8 @@ class SystemContactsFetcher: NSObject {
} }
guard granted else { guard granted else {
Logger.info("\(self.TAG) declined contact access.")
// This case should have been caught be the error guard a few lines up. // This case should have been caught be the error guard a few lines up.
assertionFailure() owsFail("\(self.TAG) declined contact access.")
DispatchQueue.main.async { DispatchQueue.main.async {
completion?(nil) completion?(nil)
} }
@ -450,8 +445,7 @@ class SystemContactsFetcher: NSObject {
} }
guard let contacts = fetchedContacts else { guard let contacts = fetchedContacts else {
Logger.error("\(self.TAG) contacts was unexpectedly not set.") owsFail("\(self.TAG) contacts was unexpectedly not set.")
assertionFailure()
completion?(nil) completion?(nil)
} }

@ -26,7 +26,7 @@ class ExperienceUpgrade: TSYapDatabaseObject {
self.image = nil self.image = nil
super.init(uniqueId: uniqueId) super.init(uniqueId: uniqueId)
} }
required init!(coder: NSCoder!) { required init!(coder: NSCoder!) {
// This is the unfortunate seam between strict swift and fast-and-loose objc // 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 // 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 self.image = nil
super.init(coder: coder) super.init(coder: coder)
} }
required init(dictionary dictionaryValue: [AnyHashable : Any]!) throws { required init(dictionary dictionaryValue: [AnyHashable : Any]!) throws {
// This is the unfortunate seam between strict swift and fast-and-loose objc // 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 // 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) return super.storageBehaviorForProperty(withKey: propertyKey)
} else { } else {
// Being conservative here in case we rename a property. // Being conservative here in case we rename a property.
assertionFailure("unknown property \(propertyKey)") owsFail("unknown property \(propertyKey)")
return super.storageBehaviorForProperty(withKey: propertyKey) return super.storageBehaviorForProperty(withKey: propertyKey)
} }
} }

@ -0,0 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
func owsFail(_ message: String) {
Logger.error(message)
Logger.flush()
assertionFailure(message)
}

@ -41,7 +41,7 @@ class AttachmentPointerView: UIView {
@available(*, unavailable) @available(*, unavailable)
override init(frame: CGRect) { 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. // This initializer should never be called, but we assign some bogus values to keep the compiler happy.
self.filename = genericFilename self.filename = genericFilename
self.isIncoming = false self.isIncoming = false
@ -53,7 +53,8 @@ class AttachmentPointerView: UIView {
@available(*, unavailable) @available(*, unavailable)
required init?(coder aDecoder: NSCoder) { 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. // This initializer should never be called, but we assign some bogus values to keep the compiler happy.
self.filename = genericFilename self.filename = genericFilename
self.isIncoming = false self.isIncoming = false

@ -52,7 +52,7 @@ import UIKit
super.init(coder: aDecoder) super.init(coder: aDecoder)
assertionFailure() owsFail("\(self.tag) Invalid constructor")
} }
public required init() { public required init() {

Loading…
Cancel
Save