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

Handle empty reponses from Google APIs for listing requests #373

Merged
merged 4 commits into from
Nov 13, 2023

Conversation

priitlatt
Copy link
Contributor

@priitlatt priitlatt commented Nov 8, 2023

Firebase releases API has started to return empty respones to listing requests. Handle those by checking if the requested resource key is present in the response object instead of failing unexpectedly with KeyError.

Example traceback:

[17:39:37 08-11-2023] INFO  acting_manager_mixin.py:42 > >>> GET https://firebaseappdistribution.googleapis.com/v1/projects/228333310124/apps/1:228333310124:ios:5e439e0d0231a788ac8f09/releases?orderBy=createTimeDesc&pageSize=1&alt=json None
[17:39:38 08-11-2023] INFO  acting_manager_mixin.py:47 > <<< {}
[17:39:38 08-11-2023] WARNING cli_app.py:121 > Executing "firebase-app-distribution get-latest-build-version" failed unexpectedly. Detailed logs are available at "/var/folders/wr/c44p23x10f302_kfbj32z0p80000gn/T/codemagic-08-11-23.log". To see more details about the error
, add "--verbose" command line option.
[17:39:38 08-11-2023] ERROR cli_app.py:123 > Exception traceback:
Traceback (most recent call last):
  File "/Users/priit/development/nevercode/cli-tools/src/codemagic/cli/cli_app.py", line 213, in invoke_cli
    CliApp._running_app._invoke_action(args)
  File "/Users/priit/development/nevercode/cli-tools/src/codemagic/cli/cli_app.py", line 170, in _invoke_action
    return cli_action(**action_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/development/nevercode/cli-tools/src/codemagic/cli/cli_app.py", line 465, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/development/nevercode/cli-tools/src/codemagic/tools/firebase_app_distribution/actions/get_latest_build_version_action.py", line 23, in get_latest_build_version
    releases = self.client.releases.list(app_identifier, limit=1)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/development/nevercode/cli-tools/src/codemagic/google/resource_managers/mixins/listing_manager_mixin.py", line 68, in list
    resources.extend(self.resource_type(**item) for item in response[self.resource_type.get_label()])
                                                            ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'releases'

Updated actions:

  • firebase-app-distribution get-latest-build-version
  • firebase-app-distribution releases list

@priitlatt priitlatt marked this pull request as ready for review November 13, 2023 08:56
Comment on lines +47 to +52
if not releases:
self.logger.info(Colors.YELLOW(f"No releases available for {app_identifier.app_id}"))
else:
printer = ResourcePrinter(json_output, self.echo)
printer.print_resources(releases, should_print)

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not releases:
self.logger.info(Colors.YELLOW(f"No releases available for {app_identifier.app_id}"))
else:
printer = ResourcePrinter(json_output, self.echo)
printer.print_resources(releases, should_print)
if not releases:
self.logger.info(Colors.YELLOW(f"No releases available for {app_identifier.app_id}"))
return []
printer = ResourcePrinter(json_output, self.echo)
printer.print_resources(releases, should_print)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In expected scenarios this equivalent to current implementations. As with the comment above, if the releases indeed comes out as None (or any other falsy equivalent), then it is better if that unexpected value somehow surfaces.

@@ -65,7 +65,9 @@ def list(
request = self._get_resources_page_request(page_request_args)
response = self._execute_request(request)
Copy link
Contributor

Choose a reason for hiding this comment

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

The response might as well be "" or even None

Suggested change
response = self._execute_request(request)
response = self._execute_request(request) or {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For listing requests? If the response indeed is something other than what we expect now (a dictionary) then I find it to be better if the request handling fails and we'll become aware of the unexpected return type instead of blindly accepting all kinds of values.

@priitlatt priitlatt merged commit 7f5f2c4 into master Nov 13, 2023
7 checks passed
@priitlatt priitlatt deleted the bugfix/firebase-api-empty-responses branch November 13, 2023 09:26
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.

2 participants