Azure / Azure/azure-cli

`az storage blob directory` failures return exit code 0

Open
#20,319 10 comments 2 reactions 1 assignee Claimed by @evelyn-ys View on GitHub
act-codegen-extensibility-squad Customer Usage customer-reported Storage
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

When running a `az storage blob directory` command which results in a failure, the exit code of the command is `0`, meaning it was successful, not `1`, which it should be on failure.

I've tried this on 2 commands:
Uploading a file:
```shell
[user@localhost ~]$ az storage blob directory upload --account-name mystorageacct --container mycontainer --destination-path / --source testfile
INFO: Scanning...
INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support

Job 9s9a9979-7838-4a42-6f79-5b150ff07611 has started
Log file is located at: /home/user/.azcopy/9s9a9979-7838-4a42-6f79-5b150ff07611.log

INFO: Authentication failed, it is either not correct, or expired, or does not have the correct permission -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /home/vsts/go/pkg/mod/github.com/!azure/azure-storage-blob-go@v0.10.0/azblob/zc_storage_error.go:42
===== RESPONSE ERROR (ServiceCode=AuthorizationFailure) =====
Description=This request is not authorized to perform this operation.
RequestId:5ec4200c-f01e-0058-451d-d803ae000000
Time:2021-11-12T23:34:30.4774040Z, Details:
Code: AuthorizationFailure
PUT https://mystorageacct.blob.core.windows.net/mycontainer//testfile?se=2021-11-13t23%3A34%3A30z&sig=-REDACTED-&sp=rwdlacup&srt=sco&ss=b&sv=2018-03-28&timeout=901
Content-Length: [10]
User-Agent: [AzCopy/10.5.0 Azure-Storage/0.10 (go1.13; linux)]
X-Ms-Blob-Cache-Control: []
X-Ms-Blob-Content-Disposition: []
X-Ms-Blob-Content-Encoding: []
X-Ms-Blob-Content-Language: []
X-Ms-Blob-Content-Md5: []
X-Ms-Blob-Content-Type: [text/plain; charset=utf-8]
X-Ms-Blob-Type: [BlockBlob]
X-Ms-Client-Request-Id: [3acf187d-c772-4474-5c7e-2d4ee178fe73]
X-Ms-Version: [2019-02-02]
--------------------------------------------------------------------------------
RESPONSE Status: 403 This request is not authorized to perform this operation.
Content-Length: [246]
Content-Type: [application/xml]
Date: [Fri, 12 Nov 2021 23:34:29 GMT]
Server: [Microsoft-HTTPAPI/2.0]
X-Ms-Client-Request-Id: [3acf187d-c772-4474-5c7e-2d4ee178fe73]
X-Ms-Error-Code: [AuthorizationFailure]
X-Ms-Request-Id: [5ec4200c-f01e-0058-451d-d803ae000000]

INFO: azcopy: A newer version 10.13.0 is available to download

0.0 %, 0 Done, 0 Failed, 1 Pending, 0 Skipped, 1 Total,

Job 9s9a9979-7838-4a42-6f79-5b150ff07611 summary
Elapsed Time (Minutes): 0.0334
Number of File Transfers: 1
Number of Folder Property Transfers: 0
Total Number of Transfers: 1
Number of Transfers Completed: 0
Number of Transfers Failed: 1
Number of Transfers Skipped: 0
TotalBytesTransferred: 0
Final Job Status: Cancelled

[user@localhost ~]$ $?
0: command not found
```

and Listing a directory:
```shell
[user@localhost ~]$ az storage blob directory list --account-name mystorageacct --container-name mycontainer --directory-path /

You do not have the required permissions needed to perform this operation.
Depending on your operation, you may need to be assigned one of the following roles:
"Storage Blob Data Contributor (Preview)"
"Storage Blob Data Reader (Preview)"
"Storage Queue Data Contributor (Preview)"
"Storage Queue Data Reader (Preview)"

If you want to use the old authentication method and allow querying for the right account key, please use the "--auth-mode" parameter and "key" value.

[user@localhost ~]$ $?
0: command not found
```

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 978a095c-3ead-282f-304f-fb627dad53a4
* Version Independent ID: 43fb2b4e-3f87-f3b8-2e85-ed5812a69ffc
* Content: [az storage blob directory](https://docs.microsoft.com/en-us/cli/azure/storage/blob/directory?view=azure-cli-latest#az_storage_blob_directory_show)
* Content Source: [latest/docs-ref-autogen/storage/blob/directory.yml](https://github.com/MicrosoftDocs/azure-docs-cli/blob/master/latest/docs-ref-autogen/storage/blob/directory.yml)
* Service: **storage**
* GitHub Login: @rloutlaw
* Microsoft Alias: **routlaw**

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.