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

The command failed with an unexpected error. Here is the traceback: 'environmentName' #36

Open
sergeibelov113 opened this issue Jul 10, 2024 · 3 comments

Comments

@sergeibelov113
Copy link

Doesn't work right on my side. When I install it through brew, aztx allows me to see and choose subscription. But when I chose any subscription and then tries to connect to kubernetes cluster for example - it throws some weird python errors regarding environmentName.

Even az account command stopped working and throws the same error. Only az account clear and az login then works.
But when I run aztx - the same issue repeats.

az account show
The command failed with an unexpected error. Here is the traceback:
'environmentName'
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 363, in handler
    show_exception_handler(ex)
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/arm.py", line 432, in show_exception_handler
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 361, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/command_modules/profile/custom.py", line 70, in show_subscription
    return profile.get_subscription(subscription)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/_profile.py", line 567, in get_subscription
    subscriptions = self.load_cached_subscriptions()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/_profile.py", line 553, in load_cached_subscriptions
    cached_subscriptions = [sub for sub in subscriptions
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/_profile.py", line 554, in <listcomp>
    if all_clouds or sub[_ENVIRONMENT_NAME] == active_cloud.name]
                     ~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'environmentName'

➜  ~ brew info aztx
==> riweston/aztx/aztx: stable 1.1.0
This tool is a helper for azure-cli that leverages fzf for a nice interface to switch between subscription contexts.
https://github.com/riweston/aztx
Not installed
From: https://github.com/riweston/homebrew-aztx/blob/HEAD/aztx.rb
License: MIT
==> Dependencies
Required: azure-cli ✔, fzf ✔
➜  ~
➜  ~
➜  ~
➜  ~
➜  ~ brew info azure-clie
Error: No available formula with the name "azure-clie". Did you mean azure-cli?
➜  ~ brew info azure-cli
==> azure-cli: stable 2.62.0 (bottled), HEAD
Microsoft Azure CLI 2.0
https://docs.microsoft.com/cli/azure/overview
Installed
/opt/homebrew/Cellar/azure-cli/2.61.0 (27,535 files, 639.6MB)
  Poured from bottle using the formulae.brew.sh API on 2024-05-21 at 22:20:37
/opt/homebrew/Cellar/azure-cli/2.62.0 (27,344 files, 634.3MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-07-10 at 11:24:41
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/a/azure-cli.rb
License: MIT
==> Dependencies
Build: pkg-config ✔, rust ✘
Required: openssl@3 ✔, [email protected] ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 22,096 (30 days), 77,234 (90 days), 321,052 (365 days)
install-on-request: 22,064 (30 days), 77,147 (90 days), 320,836 (365 days)
build-error: 50 (30 days)
@riweston
Copy link
Owner

riweston commented Jul 10, 2024

Thanks for raising this @sergeibelov113! The tool manipulates the config file azure-cli uses so there must be some bug when it tries to make the change. I'll investigate and report back 👍

@balonik
Copy link

balonik commented Dec 13, 2024

@riweston
Incompatibility might be caused by newer CLI version? The format of the config file that is now generated by az differs a lot from what is generated by aztx. There are fields missing and one of the missing fields is also environmentName which Python complains about.

az generated

{
  "installationId": "_redacted_",
  "subscriptions": [
    {
      "id": "_redacted_",
      "name": "Azure subscription 1",
      "state": "Enabled",
      "user": {
        "name": "_redacted_",
        "type": "user"
      },
      "isDefault": true,
      "tenantId": "_redacted_",
      "environmentName": "AzureCloud",
      "homeTenantId": "_redacted_",
      "tenantDefaultDomain": "_redacted_",
      "tenantDisplayName": "_redacted_",
      "managedByTenants": []
    }
  ]
}

aztx generated

{
  "installationId": "_redacted_",
  "subscriptions": [
    {
      "id": "_redacted_",
      "name": "Azure subscription 1",
      "state": "Enabled",
      "user": {
        "name": "_redacted_",
        "type": "user"
      },
      "isDefault": true
    }
  ]
}

@balonik
Copy link

balonik commented Dec 13, 2024

related to b412c78 which removed some fields and environmentName seems to be actually used by Azure CLI now.

aztx version 1.0.4 does not have this problem

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

No branches or pull requests

3 participants