Azure / azure-cli

Azure Command-Line Interface
MIT License
4.01k stars 2.98k forks source link

Suppress error in "az keyvault certificate contact list" command #28584

Open neok-g opened 7 months ago

neok-g commented 7 months ago

Describe the bug

I am trying to use this command: az keyvault certificate contact list (link).

For a keyvault that does not contain any certificate contacts the command az keyvault certificate contact list --vault-name kv-xxx prints the following error:

ERROR: (ContactsNotFound) Contacts not found Code: ContactsNotFound Message: Contacts not found

I want to suppress this error so I tried: az keyvault certificate contact list --vault-name kv-xxx --only-show-errors and az keyvault certificate contact list --vault-name kv-xxx --output none

But both without success: the error keeps showing up. How can I prevent this. I just want to use the return value/object to proceed my script.

Related command

az keyvault certificate contact list --vault-name kv-xxx az keyvault certificate contact list --vault-name kv-xxx --only-show-errors az keyvault certificate contact list --vault-name kv-xxx --output none

Errors

ERROR: (ContactsNotFound) Contacts not found Code: ContactsNotFound Message: Contacts not found

Issue script & Debug output

DEBUG: cli.knack.cli: Command arguments: ['keyvault', 'certificate', 'contact', 'list', '--vault-name', 'kv-agw-tst-001', '--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 0x0000018CCFBDB880>, <function OutputProducer.on_global_arguments at 0x0000018CCFD66020>, <function CLIQuery.on_global_arguments at 0x0000018CCFD97BA0>] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] DEBUG: cli.azure.cli.core: Modules found from index for 'keyvault': ['azure.cli.command_modules.keyvault'] DEBUG: cli.azure.cli.core: Loading command modules: DEBUG: cli.azure.cli.core: Name Load Time Groups Commands DEBUG: cli.azure.cli.core: keyvault 0.023 20 113 DEBUG: cli.azure.cli.core: Total (1) 0.023 20 113 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 20 groups, 113 commands. DEBUG: cli.azure.cli.core: Found a match in the command table. DEBUG: cli.azure.cli.core: Raw command : keyvault certificate contact list DEBUG: cli.azure.cli.core: Command table: keyvault certificate contact list DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x0000018CD2C46D40>] DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\ba_kgilliss.azure\commands\2024-03-19.15-44-58.keyvault_certificate_contact_list.10568.log'. INFO: az_command_data_logger: command args: keyvault certificate contact list --vault-name {} --debug DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x0000018CD2C53380>] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x0000018CD2CA9260>, <function register_cache_arguments..add_cache_arguments at 0x0000018CD2CA93A0>] 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 0x0000018CCFD660C0>, <function CLIQuery.handle_query_parameter at 0x0000018CCFD97C40>, <function register_ids_argument..parse_ids_arguments at 0x0000018CD2CA9300>] DEBUG: cli.azure.cli.core.auth.persistence: build_persistence: location='C:\Users\ba_kgilliss\.azure\msal_token_cache.bin', encrypt=True DEBUG: cli.azure.cli.core.auth.binary_cache: load: C:\Users\ba_kgilliss.azure\msal_http_cache.bin DEBUG: urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None) DEBUG: msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/oauth2/v2.0/devicecode', 'http_logout _supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com/43dd17eb-802f-4b5e-848d-e5052b7d2895/kerberos', 'tenant_region_scope': 'EU', 'cloud_i nstance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'} DEBUG: msal.application: Broker enabled? None DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): kv-agw-tst-001.vault.azure.net:443 DEBUG: urllib3.connectionpool: https://kv-agw-tst-001.vault.azure.net:443 "GET /certificates/contacts?api-version=7.4 HTTP/1.1" 401 97 DEBUG: cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://vault.azure.net/.default',), kwargs={'tenant_id': '43dd17eb-802f-4b5e-848d-e5052b7d2895'} DEBUG: cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://vault.azure.net/.default',), claims=None, kwargs={} DEBUG: msal.application: Cache hit an AT DEBUG: msal.telemetry: Generate or reuse correlation_id: c40e7245-ef60-465e-ad1f-3e7ad4f6b852 DEBUG: urllib3.connectionpool: https://kv-agw-tst-001.vault.azure.net:443 "GET /certificates/contacts?api-version=7.4 HTTP/1.1" 404 68 DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last): File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/keyvault/_command_type.py", line 109, in keyvault_command_handler File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/core/tracing/decorator.py", line 76, in wrapper_use_tracer File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/keyvault/certificates/_client.py", line 722, in get_contacts File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/keyvault/certificates/_generated/_operations_mixin.py", line 782, in get_certificate_contacts File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/core/tracing/decorator.py", line 76, in wrapper_use_tracer File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/keyvault/certificates/_generated/v7_4/operations/_key_vault_client_operations.py", line 1048, in get_certificate_contacts File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/core/exceptions.py", line 112, in map_error azure.core.exceptions.ResourceNotFoundError: (ContactsNotFound) Contacts not found Code: ContactsNotFound Message: Contacts not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 664, in execute File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 731, in _run_jobs_serially File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 701, in _run_job File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 334, in call File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/keyvault/_command_type.py", line 135, in keyvault_command_handler File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/keyvault/_command_type.py", line 49, in keyvault_exception_handler knack.util.CLIError: (ContactsNotFound) Contacts not found Code: ContactsNotFound Message: Contacts not found

ERROR: cli.azure.cli.core.azclierror: (ContactsNotFound) Contacts not found Code: ContactsNotFound Message: Contacts not found ERROR: az_command_data_logger: (ContactsNotFound) Contacts not found Code: ContactsNotFound Message: Contacts not found DEBUG: cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x0000018CD2C46FC0>] INFO: az_command_data_logger: exit code: 1 INFO: cli.main: Command ran in 4.839 seconds (init: 1.148, invoke: 3.691) INFO: telemetry.main: Begin splitting cli events and extra events, total events: 1 INFO: telemetry.client: Accumulated 0 events. Flush the clients. INFO: telemetry.main: Finish splitting cli events and extra events, cli events: 1 INFO: telemetry.save: Save telemetry record of length 3690 in cache INFO: telemetry.main: Begin creating telemetry upload process. INFO: telemetry.process: Creating upload process: "C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\telemetry__init__.pyc C:\Users\ba_kgilliss.azure" INFO: telemetry.process: Return from creating process INFO: telemetry.main: Finish creating telemetry upload process.

Expected behavior

A would like to suppress the error

Environment Summary

azure-cli 2.58.0

core 2.58.0 telemetry 1.1.0

Extensions: resource-graph 2.1.0

Dependencies: msal 1.26.0 azure-mgmt-resource 23.1.0b2

Additional context

No response

yonzhan commented 7 months ago

Thank you for opening this issue, we will look into it.

evelyn-ys commented 7 months ago

It should be the keyvault service that returns an empty list instead of throwing exceptions. cc @jlichwa for awareness

microsoft-github-policy-service[bot] commented 7 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @RandalliLama, @schaabs, @jlichwa.

jlichwa commented 7 months ago

That would be breaking change, since that is how it worked for years. Not sure if CLI have option to check for error and continue with script.

neok-g commented 7 months ago

It should be the keyvault service that returns an empty list instead of throwing exceptions. cc @jlichwa for awareness

That would be the expected behavior IMO