wordpress-mobile/WordPress-iOS

NSInvalidArgumentException: no object at index 6 in section at index 0

Closed this issue · 3 comments

Sentry Issue: WORDPRESS-IOS-46F4

NSInvalidArgumentException: no object at index 6 in section at index 0
  File "PostListViewController.swift", line 160, in PostListViewController.postAtIndexPath
  File "PostListViewController.swift", line 225, in PostListViewController.tableView
  File "<compiler-generated>", in thunk for closure
  File "main.swift", line 7, in main
...
(26 additional frame(s) were not displayed)

Thanks for reporting! 👍

This issue has occurred 6 times, affecting 5 different users on version 24.7. The exception was thrown from this line:

guard let post = fetchResultsController.object(at: indexPath) as? Post else {
fatalError("Expected a post object.")
}

Particularly from the object(at:) method of NSFetchedResultsController, as per the documentation:

If indexPath does not describe a valid index path in the fetch results, an exception is raised.

I wonder if there's a safer way to escape this exception and use wpAssertionFailure instead... This looks like a race between the data refreshing and the table view reloading its cells while still referring to the previous set of index paths.

Closing this as duplicate of #22181, where the expected fix will be shipped in version 24.8 as per #22181 (comment).