WordPress-iOS icon indicating copy to clipboard operation
WordPress-iOS copied to clipboard

[NotificationsViewController.selectRow] NSInternalInconsistencyException: Attempted to perform update with invalid index path: <NSIndexPath: 0x283a1b9a0> {length = 2, path...

Open jkmassel opened this issue 4 years ago • 4 comments
trafficstars

Sentry Url: https://sentry.io/share/issue/0fdb6fedd3d44625bf944ffb7c306193/ User Count: 616 Count: 803 First Release: 14.8.0.3 First Seen: 2020-09-04T04:34:54Z Last Seen: 2020-11-23T18:22:01Z 24 Hours: 216 30 Days: 763

NSInternalInconsistencyException: Invalid indexPath
  File "NotificationsViewController.swift", line 910, in NotificationsViewController.selectRow
  File "NotificationsViewController.swift", line 211, in NotificationsViewController.traitCollectionDidChange
  File "<compiler-generated>", line null, in NotificationsViewController.traitCollectionDidChange
  File "main.swift", line 7, in main
...
(70 additional frame(s) were not displayed)

jkmassel avatar Nov 23 '20 18:11 jkmassel

@jleandroperez pinging you here cause you're our notifications master, sir!

I was thinking that perhaps we can just check if the indexPath is valid before updating it? I'm just not sure if that would leave the app in a weird state somehow. Thoughts?

leandroalonso avatar Nov 24 '20 12:11 leandroalonso

@leandroalonso Hey there!! long time no see!!

As far as I understand, it's crashing in this API right?

    func selectRow(for notification: Notification, animated: Bool = true,
                   scrollPosition: UITableView.ScrollPosition = .none) {
        selectedNotification = notification

        if let indexPath = tableViewHandler.resultsController.indexPath(forObject: notification), indexPath != tableView.indexPathForSelectedRow {
            DDLogInfo("\(self) \(#function) Selecting row at \(indexPath) for Notification: \(notification.notificationId) (\(notification.type ?? "Unknown type")) - \(notification.title ?? "No title")")
            tableView.selectRow(at: indexPath, animated: animated, scrollPosition: scrollPosition)
        }
    }

Invalid Index Path makes me think that the resultsController.indexPath(forObject:) invocation succeeds, but the TableView is unaware of such path.

I'd say that the table (for whatever reason) got Out of Sync with the NSFetchedResultsController. I would suspect of:

  • This method being executed in a BG thread?
  • A reloadData invocation happening somewhere

Note that, it's possible, at that point the TableView is already in a broken state. You could probably detect such scenario (by checking if the IndexPath is out of bounds), and, as you mentioned, perhaps invoke reloadData.

P.s.: Mother of god, when did this ViewController get 1800 LOC!!!

jleandroperez avatar Nov 24 '20 13:11 jleandroperez

Raising to high priority because it's showing a high number of users affected. I don't think it's a new issue though 🤔 I think this issue is a continuation of https://github.com/wordpress-mobile/WordPress-iOS/issues/15092 which came to a full stop on Nov 20 and this one picked up steam at the exact same time. Something seems to have gotten rejiggered in Sentry.

Events in the last 90d: 4,300 Users affected in the last 90d: 2,300 WORDPRESS-IOS-38WR: https://sentry.io/share/issue/0fdb6fedd3d44625bf944ffb7c306193/

image

designsimply avatar Dec 11 '20 01:12 designsimply

This issue was addressed in this PR, but the fix resulted in a new bug:

The app crashes in selectRow method, likely due to an attempt to get the number of rows of a section that doesn't exist.

CleanShot 2024-03-07 at 01 01 51

tableView.numberOfRows(inSection: indexPath.section)

I think the app crashes if the given indexPath.section doesn't exist.

I've assigned you this issue @dvdchr since you've worked on it before, but feel free to un-assign yourself if you're not planning to continue working on it.

salimbraksa avatar Mar 07 '24 00:03 salimbraksa

This only happens in very old versions of the app, so it can be closed.

jkmassel avatar Aug 27 '24 23:08 jkmassel