fix: Catch and swallow snackbar exception (#536)

For reasons not fully understood the root of a fragment's view might not
have relevant view from the activity set as its parent. This causes
`Snackbar.make()` to throw an exception, and crash.

See https://issuetracker.google.com/issues/228215869.

For now, "fix" this by swallowing the exception. Not showing the error
is better than crashing.
This commit is contained in:
Nik Clayton 2024-03-16 14:34:21 +01:00 committed by GitHub
parent bdbe2f85c2
commit 9535506596
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 3 deletions

View File

@ -127,9 +127,16 @@ abstract class SFragment<T : IStatusViewData> : Fragment(), StatusActionListener
it.msg(requireContext()),
)
Timber.e(msg)
try {
Snackbar.make(requireView(), msg, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.action_retry) { serverRepository.retry() }
.show()
} catch (e: IllegalArgumentException) {
// On rare occasions this code is running before the fragment's
// view is connected to the parent. This causes Snackbar.make()
// to crash. See https://issuetracker.google.com/issues/228215869.
// For now, swallow the exception.
}
serverCanTranslate = false
}
}