From d63d66baf7b68f7c54062443149b5708d867d9b4 Mon Sep 17 00:00:00 2001 From: Gino Miceli Date: Fri, 1 Mar 2024 14:45:31 -0500 Subject: [PATCH] Fail gracefully on race conditions --- .../home/mapcontainer/HomeScreenMapContainerFragment.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt b/ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt index f3d8500bfd..24cae8fa69 100644 --- a/ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt @@ -51,6 +51,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import timber.log.Timber /** Main app view, displaying the map and related controls (center cross-hairs, add button, etc). */ @AndroidEntryPoint @@ -139,9 +140,13 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() { * This method should only be called after view creation. */ private suspend fun showDataCollectionHint() { - check(this::mapContainerViewModel.isInitialized) { "mapContainerViewModel not initialized" } - check(this::binding.isInitialized) { "binding not initialized" } + if (!this::mapContainerViewModel.isInitialized) { + return Timber.w("showDataCollectionHint() called before mapContainerViewModel initialized") + } mapContainerViewModel.surveyUpdateFlow.collect { + if (!this::binding.isInitialized) { + return@collect Timber.w("showDataCollectionHint() called before binding initialized") + } val messageId = when { it.addLoiPermitted -> R.string.suggest_data_collection_hint