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

Fix crash on autocomplete error #734

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

arnaud33200
Copy link

fix a crash when there is an error result for autocompleteLauncher

Fixes #733 🦕

Copy link

google-cla bot commented Aug 29, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dkhawk
Copy link
Contributor

dkhawk commented Oct 7, 2024

Thanks for opening this PR!

Before we merge it, could you please

  1. take a look at the Contributor License Agreement (CLA) and,

  2. take a look at the commit messages? We're using Conventional Commits to help keep our commit history organized, and it looks like this doesn't follow that format. Also, please update the PR title to have a conventional commit prefix.

Thanks again and let me know if you have any questions!

@kikoso
Copy link
Collaborator

kikoso commented Nov 1, 2024

Hi @arnaud33200 ! Did you have the chance to take a look at the message above? We would need you to sign the CLA, and also to rewrite the commit title/message to follow the conventional commit guidelines.

Let us know if you have any further questions, thanks!

Comment on lines +144 to +145
val status = Autocomplete.getStatusFromIntent(result.data)
binding.response.text = "Error: ${status.statusMessage}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This has a potential NPE. How about the following change?

Suggested change
val status = Autocomplete.getStatusFromIntent(result.data)
binding.response.text = "Error: ${status.statusMessage}"
binding.response.text = result.data?.let { intent ->
getString(
R.string.error_message,
Autocomplete.getStatusFromIntent(intent).statusMessage
)
} ?: getString(R.string.error_unknown)

And add the following to demo-kotlin/app/src/main/res/values/strings.xml

<!-- message to show for errors received from the API. -->
  <string name="error_message" translatable="false">Error: %1$s</string>

  <!-- message to show if the error status is unavailable. -->
  <string name="error_unknown" translatable="false">Unexpected error</string>

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.

PlaceAutocompleteActivity crash
4 participants