Discarding all local drafts from the dashboard card leads to a crash
Expected behavior
The app shouldn't crash.
Actual behavior
Discarding local drafts from the dashboard card crashes the app after the final draft is discarded.
Steps to reproduce the behavior
- Launch the Jetpack app.
- Switch to a site that preferably has no draft posts.
- Create a local-only draft by either: a. Create a blog post > enter in some title and body content > kill app, OR b. Switching to airplane mode and creating a new blog post, OR
- From the Home Dashboard, scroll down and find the Drafts card.
- Tap the draft > Tap close > Discard. Continue until all drafts are discarded.
- Verify that the app crashed.
Here's the error stack trace:
CoreData: error: NSFetchedResultsController: no object at index 0 in section at index 0
2023-07-23 13:48:28.188910+0700 Jetpack[57449:15317007] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'no object at index 0 in section at index 0'
*** First throw call stack:
(
0 CoreFoundation 0x000000011bf56330 __exceptionPreprocess + 172
1 libobjc.A.dylib 0x000000010eb45274 objc_exception_throw + 56
2 CoreData 0x000000010f361aa4 -[NSFetchedResultsController indexPathForObject:] + 0
3 Jetpack 0x0000000104f554d0 $s9WordPress18PostsCardViewModelC6postAtyAA4PostC10Foundation9IndexPathVF + 360
4 Jetpack 0x0000000105d41bd0 $s9WordPress26DashboardPostsListCardCellC9tableView_14didSelectRowAtySo07UITableI0C_10Foundation9IndexPathVtF + 164
5 Jetpack 0x0000000105d41ff4 $s9WordPress26DashboardPostsListCardCellC9tableView_14didSelectRowAtySo07UITableI0C_10Foundation9IndexPathVtFTo + 136
6 UIKitCore 0x0000000142de62b8 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:isCellMultiSelect:deselectPrevious:performCustomSelectionAction:] + 1208
7 UIKitCore 0x0000000142de65c8 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 252
8 UIKitCore 0x00000001430619e8 -[_UIAfterCACommitBlock run] + 64
9 UIKitCore 0x0000000143061e14 -[_UIAfterCACommitQueue flush] + 164
10 UIKitCore 0x0000000142c1fce8 _runAfterCACommitDeferredBlocks + 492
11 UIKitCore 0x0000000142c11a6c _cleanUpAfterCAFlushAndRunDeferredBlocks + 104
12 UIKitCore 0x0000000142c3bd50 _afterCACommitHandler + 60
13 CoreFoundation 0x000000011beb8c10 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
14 CoreFoundation 0x000000011beb357c __CFRunLoopDoObservers + 512
15 CoreFoundation 0x000000011beb3a20 __CFRunLoopRun + 948
16 CoreFoundation 0x000000011beb3254 CFRunLoopRunSpecific + 584
17 GraphicsServices 0x0000000124b9fc9c GSEventRunModal + 160
18 UIKitCore 0x0000000142c12ff0 -[UIApplication _run] + 868
19 UIKitCore 0x0000000142c16f3c UIApplicationMain + 124
20 Jetpack 0x0000000105ee3410 main + 496
21 dyld 0x000000010e6e9514 start_sim + 20
22 ??? 0x000000010e5f5f28 0x0 + 4536098600
23 ??? 0x7c44000000000000 0x0 + 8954281959119388672
)
Tested on iPhone 14 Simulator, iOS 16.4, Jetpack iOS 22.8
Hey, @dvdchr. Were you able to reproduce it more than once? Can you think of any other required steps? I've tried it now but wasn't able to repro the crash.
I also searched for this stack trace in Sentry and haven't found any similar crashes.
Hey @kean, I was able to reproduce it consistently at the time, but it didn't seem to occur again after I gave it another try on the latest trunk branch 🤔 .
I took a video before creating this issue, but it's just a record of the reproduction steps. The only difference is that there are multiple unsynced drafts, and I'm pretty sure that there aren't any draft posts for the site. I'll DM the video to you in case it's helpful.
Thanks! I've searched on Sentry and couldn't find anything related to this stacktrace in the latest couple of releases.