az cli incorrectly returns exit code 0 even on failure
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
### Describe the bug
The command `az account list` silently fails when not already logged in and the process returns exit code `0`. This makes breaks Unix convention and makes it more difficult in automation to detect failure.
### Related command
`az account list` compared with `az account show` that provides the correct exit code.
```bash
$ az account list
Please run "az login" to access your accounts.
[]
$ echo $?
0
$ az account show
Please run 'az login' to setup account.
$ echo $?
1
```
### Errors
no error - which is the problem
### Issue script & Debug output
```bash
$ az account list --debug
cli.knack.cli: Command arguments: ['account', 'list', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [, , ]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'account': ['azure.cli.command_modules.profile', 'azure.cli.command_modules.resource']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: profile 0.002 2 8
cli.azure.cli.core: resource 0.098 51 228
cli.azure.cli.core: Total (2) 0.100 53 236
cli.azure.cli.core: Loaded 52 groups, 236 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : account list
cli.azure.cli.core: Command table: account list
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate []
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/vscode/.azure/commands/2024-03-07.10-12-22.account_list.9263.log'.
az_command_data_logger: command args: account list --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [.add_subscription_parameter at 0x7fc50b51d4e0>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [.add_ids_arguments at 0x7fc50b51f6a0>, .add_cache_arguments at 0x7fc50b51f7e0>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [, , .parse_ids_arguments at 0x7fc50b51f740>]
cli.azure.cli.command_modules.profile.custom: Please run "az login" to access your accounts.
cli.knack.cli: Event: CommandInvoker.OnTransformResult [, ]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
[]
cli.knack.cli: Event: Cli.SuccessfulExecute []
cli.knack.cli: Event: Cli.PostExecute []
az_command_data_logger: exit code: 0
cli.__main__: Command ran in 0.205 seconds (init: 0.098, invoke: 0.106)
```
### Expected behavior
exit code of `1` similar to `az account show`
### Environment Summary
```bash
$ az --version
azure-cli 2.57.0 *
core 2.57.0 *
telemetry 1.1.0
Dependencies:
msal 1.26.0
azure-mgmt-resource 23.1.0b2
Python location '/usr/local/pipx/venvs/azure-cli/bin/python'
Extensions directory '/home/vscode/.azure/cliextensions'
Python (Linux) 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
```
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.