@@ -28,6 +28,7 @@ import com.owncloud.android.lib.common.utils.Log_OC
2828import com.owncloud.android.ui.asynctasks.GetRemoteFileTask
2929import com.owncloud.android.ui.fragment.UnifiedSearchFragmentScreenState
3030import javax.inject.Inject
31+ import kotlinx.coroutines.CoroutineExceptionHandler
3132import kotlinx.coroutines.Dispatchers
3233import kotlinx.coroutines.launch
3334import kotlinx.coroutines.withContext
@@ -59,6 +60,10 @@ class UnifiedSearchViewModel(application: Application) :
5960 private var results: MutableMap <ProviderID , UnifiedSearchMetadata > = mutableMapOf ()
6061 private var searchResultsVersion = 0
6162
63+ private val sectionBuildErrorHandler = CoroutineExceptionHandler { _, throwable ->
64+ Log_OC .e(TAG , " Cannot build search result sections" , throwable)
65+ }
66+
6267 override val screenState: MutableLiveData <UnifiedSearchFragmentScreenState > =
6368 MutableLiveData (UnifiedSearchFragmentScreenState .ShowingContent )
6469 override val isLoading = MutableLiveData (false )
@@ -208,7 +213,7 @@ class UnifiedSearchViewModel(application: Application) :
208213
209214 val version = ++ searchResultsVersion
210215
211- viewModelScope.launch(Dispatchers .IO ) {
216+ viewModelScope.launch(Dispatchers .IO + sectionBuildErrorHandler ) {
212217 val sections = buildSections(snapshot)
213218
214219 withContext(Dispatchers .Main ) {
@@ -274,6 +279,11 @@ class UnifiedSearchViewModel(application: Application) :
274279 this .connectivityService = connectivityService
275280 }
276281
282+ @VisibleForTesting
283+ fun setCurrentAccountProvider (currentAccountProvider : CurrentAccountProvider ) {
284+ this .currentAccountProvider = currentAccountProvider
285+ }
286+
277287 override fun updateScreenState (state : UnifiedSearchFragmentScreenState ) {
278288 screenState.value = state
279289 }
0 commit comments