From 2cd2596ddc88b2906081acd6971d17a0b80259cf Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 31 Aug 2017 12:31:13 -0400 Subject: [PATCH] crashfix: thread.uniqueId is sometimes nil in production fail early and print diagnostics // FREEBIE --- .../ConversationView/MessagesViewController.m | 13 +++++++++++-- Signal/src/ViewControllers/SignalsViewController.m | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index b72051dc2..2dd5a2faa 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -487,8 +487,17 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { _callOnOpen = callOnViewAppearing; [self.uiDatabaseConnection beginLongLivedReadTransaction]; - self.messageMappings = - [[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] view:TSMessageDatabaseViewExtensionName]; + + if (thread.uniqueId.length > 0) { + self.messageMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] + view:TSMessageDatabaseViewExtensionName]; + } else { + OWSFail(@"uniqueId unexpectedly empty for thread: %@", thread); + self.messageMappings = + [[YapDatabaseViewMappings alloc] initWithGroups:@[] view:TSMessageDatabaseViewExtensionName]; + return; + } + // We need to impose the range restrictions on the mappings immediately to avoid // doing a great deal of unnecessary work and causing a perf hotspot. [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 86d63a7be..57f6be088 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -726,6 +726,11 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing callOnViewAppearing:(BOOL)callOnViewAppearing { + if (thread == nil) { + OWSFail(@"Thread unexpectedly nil"); + return; + } + // We do this synchronously if we're already on the main thread. DispatchMainThreadSafe(^{ MessagesViewController *mvc = [[MessagesViewController alloc] initWithNibName:@"MessagesViewController"