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

Failure modes of current_location request not accomodated #2878

Open
freakboy3742 opened this issue Sep 30, 2024 · 1 comment
Open

Failure modes of current_location request not accomodated #2878

freakboy3742 opened this issue Sep 30, 2024 · 1 comment
Labels
android The issue relates to Android mobile support. bug A crash or error in behavior.

Comments

@freakboy3742
Copy link
Member

freakboy3742 commented Sep 30, 2024

Describe the bug

According to the Android documentation, it is possible for a one-time location request to fail; in which case, a location of null is returned. However, Toga's location service currently expects that the location is non-null.

Steps to reproduce

This is difficult to reproduce specifically as it depends on a location lookup failure from the location service; however, if your code contains a one-time location request:

location = await self.location.current_location()

it is possible for the underlying getCurrentLocation() call to pass a value of null to the Consumer, resulting in the error:

E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.example.astrofilter, PID: 19840
E/AndroidRuntime: com.chaquo.python.PyException: AttributeError: 'NoneType' object has no attribute 'getLatitude'
E/AndroidRuntime:   at <python>.toga_android.hardware.location.toga_location(location.py:17)
E/AndroidRuntime:   at <python>.toga_android.hardware.location.accept(location.py:41)
E/AndroidRuntime:   at <python>.chaquopy_java.call(chaquopy_java.pyx:354)

Expected behavior

If the location service can't obtain a GPS read, it should raise an error rather than crashing.

Screenshots

No response

Environment

  • Operating System: Android
  • Python version: All
  • Software versions:
    • Briefcase: 0.3.19
    • Toga: 0.4.7+

Logs

No response

Additional context

iOS/macOS already handles this edge by raising a RuntimeError from the locationManager:didFailWithError: delegate method.

The Android testbed probe currently raises an xfail in the simulate_location_error handler; this should be returning a None result to the consumer (i.e., the same implementation as simulate_current_location, but passing a None value to the accept call).

@freakboy3742 freakboy3742 added bug A crash or error in behavior. android The issue relates to Android mobile support. labels Sep 30, 2024
@rmartin16
Copy link
Member

I was able to reproduce the error by disabling Location in the Android settings within the emulator.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android The issue relates to Android mobile support. bug A crash or error in behavior.
Projects
None yet
Development

No branches or pull requests

2 participants