codemagic-ci-cd / cli-tools

Various utilities to managing Android and iOS app builds, code signing, and deployment.
https://codemagic.io/start/
GNU General Public License v3.0
243 stars 42 forks source link

Improve general error message for unexpected failures #364

Closed priitlatt closed 10 months ago

priitlatt commented 10 months ago

If action terminates unexpectedly with an error, then the error message that is shown to users has several issues.

Consider the following error for example:

$ google-play  get-latest-build-number --package-name "${UNDEFINED_PACKAGE_NAME}" --tracks "${UNDEFINED_TRACK_NAME}"                                                                        9 ↵
Get package "None" latest build number from track ""
Executing GooglePlay action get-latest-build-number failed unexpectedly. Detailed logs are available at "/var/folders/wr/c44p23x10f302_kfbj32z0p80000gn/T/codemagic-24-10-23.log". To see more details about the error, add `--verbose` command line option.

Here we can see that:

  1. The class name of the tool is shown instead of the tool's executable name, which is little to no use for users.
  2. If the invoked action is wrapped into action group, such as app-store-connect apps get, then the action group portion if completely omitted from log output,
  3. Using --verbose does not actually show more details about the error in log output.

This PR aims to resolve the issues listed above:

  1. Executable name is displayed in the error message.
  2. Full executed command (without argument) is shown in the log output.
  3. If --verbose flag is used, then exception stacktrace is included in stdout log output.

All in all the formatted error looks as follows:

$ app-store-connect apps get invalid-app-id --verbose
[15:24:14] WARNING > Executing "app-store-connect apps get" failed unexpectedly. Detailed logs are available at "/var/folders/wr/c44p23x10f302_kfbj32z0p80000gn/T/codemagic-24-10-23.log".
[15:24:14] ERROR > 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/_app_store_connect/action_groups/apps_action_group.py", line 39, in get_app
    _ = 1 / 0
        ~~^~~
ZeroDivisionError: division by zero

Or without --verbose logging:

$ app-store-connect apps get invalid-app-id
Executing "app-store-connect apps get" failed unexpectedly. Detailed logs are available at "/var/folders/wr/c44p23x10f302_kfbj32z0p80000gn/T/codemagic-24-10-23.log". To see more details about the error, add "--verbose" command line option.