-
Notifications
You must be signed in to change notification settings - Fork 115
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
ViewModel is now access based on taskId using Bundle #2748
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2748 +/- ##
============================================
- Coverage 60.93% 60.86% -0.08%
Complexity 1158 1158
============================================
Files 264 264
Lines 6077 6117 +40
Branches 840 855 +15
============================================
+ Hits 3703 3723 +20
- Misses 1901 1914 +13
- Partials 473 480 +7
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anandwana001 Could you please do the same for other TaskFragments, either in this PR or in a follow-up?
…ent-fix' into anandwana001/2725/fragment-argument-fix
...com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt
Outdated
Show resolved
Hide resolved
...va/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskFragment.kt
Outdated
Show resolved
Hide resolved
} catch (e: Exception) { | ||
Timber.e("CaptureLocationTaskMapFragment - $e") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please cleanup the debug logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need this, so that we can get in production, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add the new method, FirebaseCrashLogger().logException(t)
here if it's safe to do so, and in the other log areas?
And one more thing, by catching the error without rethrowing it, the app will be in a weird state where no viewModel
is set and we skip everything that is in the isInitialized
check. But these are critical for the functionality of the app, like updating map pins or capturing the location.
My question is, if the app finds itself in an impossible to recover state like this, should we log the exception and try to continue, or should we go back to the home screen and show and error to the user "An unexpected error has occurred. Please try again or contact your survey organizer"? I'm not sure how to do that off the top of my head, so maybe just navigate to the home screen after logging. Also true for below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better that the app crashes than remains in an invalid state. But if we know that that can happen, we should try to fix the root cause rather than eating the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, @anandwana001 messages logged with Timber.e()
aren't captured anywhere in prod. If you need to communicate critical debug info via Crashlytics, the method @sufyanAbbasi mentioned should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it a regular error handling where we pass arguments to a new fragment and use it?
Not in a weird app state because this is something required to do.
yes, we can use FirebaseCrashLogger().logException(t)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better that the app crashes than remains in an invalid state. But if we know that that can happen, we should try to fix the root cause rather than eating the exception.
This is more of a workaround we can do and user can just do a back and forth and keep continuing the data collection, no more crashes.
Later, as a core solution, we can work on the abstract layer and the ViewModel and support the orientation change to work things better
@gino-m
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it a regular error handling where we pass arguments to a new fragment and use it?
Not sure what you mean about passing arguments to a new fragment is a regular error handling.. Can you rephrase?
Not in a weird app state because this is something required to do.
It's generally considered bad practice to catch Throwable
without managing potential consequences. The app will be in an invalid state if the view model couldn't be set since the view requires it to function, no?
...src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropPinTaskFragment.kt
Outdated
Show resolved
Hide resolved
.../main/java/com/google/android/ground/ui/datacollection/tasks/point/DropPinTaskMapFragment.kt
Outdated
Show resolved
Hide resolved
.../main/java/com/google/android/ground/ui/datacollection/tasks/point/DropPinTaskMapFragment.kt
Outdated
Show resolved
Hide resolved
.../main/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragment.kt
Outdated
Show resolved
Hide resolved
...in/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskMapFragment.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much! I'm not Android expert enough to be able to verify the correctness of this, at least not without pulling your PR and giving it a test, but I had a bigger question about error handling here, since swallowing the error means the app is in an even weirder state.
@gino-m, do you have any thoughts about how to handle these irrecoverable states without crashing?
} catch (e: Exception) { | ||
Timber.e("CaptureLocationTaskMapFragment - $e") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add the new method, FirebaseCrashLogger().logException(t)
here if it's safe to do so, and in the other log areas?
And one more thing, by catching the error without rethrowing it, the app will be in a weird state where no viewModel
is set and we skip everything that is in the isInitialized
check. But these are critical for the functionality of the app, like updating map pins or capturing the location.
My question is, if the app finds itself in an impossible to recover state like this, should we log the exception and try to continue, or should we go back to the home screen and show and error to the user "An unexpected error has occurred. Please try again or contact your survey organizer"? I'm not sure how to do that off the top of my head, so maybe just navigate to the home screen after logging. Also true for below.
.../main/java/com/google/android/ground/ui/datacollection/tasks/point/DropPinTaskMapFragment.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
override fun onMapCameraMoved(position: CameraPosition) { | ||
super.onMapCameraMoved(position) | ||
viewModel.updateCameraPosition(position) | ||
if (this@DropPinTaskMapFragment::viewModel.isInitialized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swallowing the invalid state here as well will make the issue impossible to identify in prod and even difficult to find locally.
…ent-fix' into anandwana001/2725/fragment-argument-fix
solved in PR #2761 (review) |
Fixes #2725
@shobhitagarwal1612 @gino-m @sufyanAbbasi PTAL?