zulip/zulip-mobile

Opening a notification for nonexistent user/stream causes crash

Open

#4,309 opened on Nov 12, 2020

View on GitHub
 (6 comments) (0 reactions) (0 assignees)JavaScript (673 forks)github user discovery
a-notificationshelp wantedsevere: crash

Repository metrics

Stars
 (1,348 stars)
PR merge metrics
 (PR metrics pending)

Description

This is a situation that's only possible in the first place when caused by some bug in either the app or the server. But such bugs happen, and particularly because it involves the server, we should be robust enough not to crash on it.

I don't think there's a known way to trigger this with a current version from master (or with today's release v27.157, now in alpha) and a stock server. But one way to trigger it is by reproducing #4290 on the current production release, v27.156. As described at https://github.com/zulip/zulip-mobile/issues/4290#issuecomment-726387004 , the app crashes, and (on Android) adb logcat shows output like this:

11-12 14:38:49.964 27558 27719 W ReactNativeJS: notification realm_uri not found in accounts
11-12 14:38:49.965 27558 27719 W ReactNativeJS:     realm_uri: "https://chat.zulip.org"
11-12 14:38:49.965 27558 27719 W ReactNativeJS:     known_urls: …
11-12 14:38:50.002 27558 27719 E ReactNativeJS: Error: getUserForEmail: missing user: email …

That is, we try to navigate to the right conversation as if it were on the active account... and when there isn't a user by that email, we crash.

Instead, we should handle this in getNarrowFromNotificationData -- that's the place where we take the raw names/IDs the server put in the notification and turn them into values we'll pass around to the "soft center" of our normal app code which assumes the data it gets is well-formed.

In getNarrowFromNotificationData, we should confirm that the specified user(s) or stream exist in our data. If they don't, then treat it much like we do in getAccountFromNotificationData:

  • Log a warning (to Sentry.)
  • Return null, to skip trying to do anything with the data.

That way the app will be open and running, and not crashed.

Contributor guide