Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling for urlConnection #2902

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

anandwana001
Copy link
Collaborator

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 21 lines in your changes missing coverage. Please review.

Project coverage is 63.45%. Comparing base (e093874) to head (48890ae).

Files with missing lines Patch % Lines
...lineareas/selector/OfflineAreaSelectorViewModel.kt 6.25% 15 Missing ⚠️
...flineareas/selector/OfflineAreaSelectorFragment.kt 50.00% 1 Missing and 4 partials ⚠️
...android/ground/repository/OfflineAreaRepository.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2902      +/-   ##
============================================
- Coverage     63.55%   63.45%   -0.11%     
- Complexity     1242     1243       +1     
============================================
  Files           267      267              
  Lines          6506     6523      +17     
  Branches        911      915       +4     
============================================
+ Hits           4135     4139       +4     
- Misses         1785     1795      +10     
- Partials        586      589       +3     
Files with missing lines Coverage Δ
...le/android/ground/ui/map/gms/mog/UrlInputStream.kt 0.00% <ø> (ø)
...android/ground/repository/OfflineAreaRepository.kt 49.18% <0.00%> (ø)
...flineareas/selector/OfflineAreaSelectorFragment.kt 40.32% <50.00%> (-0.42%) ⬇️
...lineareas/selector/OfflineAreaSelectorViewModel.kt 25.92% <6.25%> (-1.86%) ⬇️

@gino-m
Copy link
Collaborator

gino-m commented Dec 12, 2024

We should handle the error upstream where it can actually be addressed:

viewModelScope.launch(ioDispatcher) {
offlineAreaRepository.downloadTiles(viewport!!).collect { (bytesDownloaded, totalBytes) ->
val progressValue =
if (totalBytes > 0) {
(bytesDownloaded.toFloat() / totalBytes.toFloat()).coerceIn(0f, 1f)
} else {
0f
}
downloadProgress.postValue(progressValue)
}
isDownloadProgressVisible.postValue(false)
_navigate.emit(UiState.OfflineAreaBackToHomeScreen)
}
}

You would add .catch{} before collect to handle the failure (show a toast and close the dialog).

Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few requests, LG

anandwana001 and others added 12 commits December 17, 2024 12:32
…-timeout-exception' into anandwana001/2683/prevent-socket-timeout-exception
…xception

# Conflicts:
#	app/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt
#	app/src/test/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModelTest.kt
…xception

# Conflicts:
#	app/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt
#	app/src/test/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragmentTest.kt
Comment on lines +74 to +75
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Can it be removed given that coroutines aren't getting suspended.

downloadJob = viewModelScope.launch(ioDispatcher) {
offlineAreaRepository
.downloadTiles(viewport!!)
.catch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log the exception to timber?

Comment on lines +140 to +141
viewModel.isFailure.observeForever(isFailureObserver)
viewModel.isFailure.postValue(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to call the download flow and mock the downloadTiles to throw an error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App Crash - While Downloading Area
4 participants