Azure / Azure/azure-cli

sys.exit(3) prevents me from handling exception

Open
#30,895 3 comments 0 reactions 0 assignees View on GitHub
act-observability-squad Auto-Assign Auto-Resolve bug Container Instances customer-reported Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

Sys.exit(3) is called when a resource is not found, and since azure-cli is also a python pip package that can be used as an API in python programs, I can't handle this exception myself because the program just exits. I would recommend not doing the sys.exit(3) and allowing exception handling.

https://github.com/Azure/azure-cli/blob/610453d14e73a7d6b2da5fefc5c3f1e5538e5853/src/azure-cli-core/azure/cli/core/commands/arm.py#L431

### Related command

az container show

### Errors

ERROR:cli.azure.cli.core.azclierror:(ResourceNotFound) The Resource 'Microsoft.ContainerInstance/containerGroups/xxxxxxxx' under resource group 'xxxxxx' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound

### Issue script & Debug output

ERROR:cli.azure.cli.core.azclierror:(ResourceNotFound) The Resource 'Microsoft.ContainerInstance/containerGroups/xxxxxxxx' under resource group 'xxxxxx' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound

The arm requests are not logged even in --debug mode, Maybe this is because of the systemexit()? I get the non-debug output as shown above, but no ARM requests. I'm sure about this because my program executes other az cli commands that all show ARM requests being logged, except for this call to az container show.

### Expected behavior

Raising an exception

### Environment Summary

azure-cli 2.67.0
azure-cli-core 2.67.0

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.