Skip to content

[Issue] azd init fails in debug mode when az defaults.location isn't set #539

Description

@weikanglim

Output from azd version
Run azd version and copy and paste the output here:
azd version 0.1.0-beta.4 (commit fd96b3e)

Output from az version
Run az version and copy and paste the output here (minimum required version is 2.38.0):
{
"azure-cli": "2.38.0",
"azure-cli-core": "2.38.0",
"azure-cli-telemetry": "1.0.6",
"extensions": {
"azure-devops": "0.22.0",
"resource-graph": "2.1.0"
}
}

Describe the bug
When --debug flag is passed, azd fails to detect the az default location correctly and exits. Note: this issue has been existed for a few versions.

To Reproduce

  1. Run az config unset defaults.location
  2. Verify unset: az config get defaults.location --output json should return the message: Configuration 'defaults.location' is not set.
  3. Run azd init --template cosmos-dotnet-core-todo-app --debug in an empty folder
  4. Type in an environment name
  5. The app exits when attempting to parse the default location from az

Actual:

Error: loading environment: initializing environment: prompting for location: detecting default location: failed running config get: exit code: 1, stdout: , stderr: DEBUG: cli.knack.cli: Command arguments: ['config', 'get', 'defaults.location', '--output', 'json', '--debug']
DEBUG: cli.knack.cli: __init__ debug log:
Cannot enable color.
DEBUG: cli.knack.cli: Event: Cli.PreExecute []
DEBUG: cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x0362BCD0>, <function OutputProducer.on_global_arguments at 0x03B1C610>, <function CLIQuery.on_global_arguments at 0x03B30268>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
DEBUG: cli.azure.cli.core: Modules found from index for 'config': ['azure.cli.command_modules.config']
DEBUG: cli.azure.cli.core: Loading command modules:
DEBUG: cli.azure.cli.core: Name                  Load Time    Groups  Commands
DEBUG: cli.azure.cli.core: config                    0.008         2         7
DEBUG: cli.azure.cli.core: Total (1)                 0.008         2         7
DEBUG: cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
DEBUG: cli.azure.cli.core: Loading extensions:
DEBUG: cli.azure.cli.core: Name                  Load Time    Groups  Commands  Directory
DEBUG: cli.azure.cli.core: Total (0)                 0.000         0         0
DEBUG: cli.azure.cli.core: Loaded 2 groups, 7 commands.
DEBUG: cli.azure.cli.core: Found a match in the command table.
DEBUG: cli.azure.cli.core: Raw command  : config get defaults.location
DEBUG: cli.azure.cli.core: Command table: config get
DEBUG: cli.azure.cli.core: remaining    :            defaults.location
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x04C10EC8>]
DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\weilim\.azure\commands\2022-08-29.08-46-05.config_get.33148.log'.
INFO: az_command_data_logger: command args: config get {} --output {} --debug
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x04C49D18>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x04C49DA8>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x04C6D340>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x03B1C658>, <function CLIQuery.handle_query_parameter at 0x03B302B0>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x04C6D2F8>]
WARNING: Command group 'config' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
DEBUG: cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
DEBUG: cli.azure.cli.core.util: Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/config/custom.py", line 76, in config_get
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/config/custom.py", line 78, in config_get
knack.util.CLIError: Configuration 'defaults.location' is not set.

ERROR: cli.azure.cli.core.azclierror: Configuration 'defaults.location' is not set.
ERROR: az_command_data_logger: Configuration 'defaults.location' is not set.
DEBUG: cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x04C12028>]
INFO: az_command_data_logger: exit code: 1
INFO: cli.__main__: Command ran in 1.624 seconds (init: 1.244, invoke: 0.380)
INFO: telemetry.save: Save telemetry record of length 3026 in cache
WARNING: telemetry.check: Negative: The C:\Users\weilim\.azure\telemetry.txt was modified at 2022-08-29 08:43:31.791214, which in less than 600.000000 s
: exit status 1

Expected behavior
azd should handle the unset behavior

Environment
Information on your environment:
* Language name and version
* IDE and version : [e.g. Visual Studio 16.3]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core-cliCLI commands, cmd/, internal/cmd/bugSomething isn't working

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions