aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

aws s3 rm doesn't indicate failure on invalid files

Open CyMule opened this issue 3 years ago • 3 comments

Describe the bug

There is no indication of failure when you try to remove a file that doesn't exist. When you successfully remove a file with the command aws s3 rm s3://bucket/file-that-DOES-exist you receive the message delete: s3://bucket/file-that-DOES-exist in stdout along with exit code 0.

When you ATTEMPT to remove a file with the command aws s3 rm s3://bucket/file-that-DOES-NOT-exist you receive the message delete: s3://bucket/file-that-DOES-NOT-exist in stdout along with exit code 0.

Expected Behavior

aws cli should return a non-zero exit code along with and error message in stderr indicating that the specified file does not exist.

Current Behavior

Attempting to delete a file that doesn't exist gives you the exit code 0 and delete: s3://bucket/file-that-doesnt-exist in stdout leaving no indication of failure.

Reproduction Steps

Attempt to remove a file that doesn't exist: aws s3 rm s3://bucket/file-that-DOES-NOT-exist

In stdout you will receive: delete: s3://bucket/file-that-DOES-NOT-exist

Check exit code: echo $?

You will receive: 0

Possible Solution

aws cli should return a non-zero exit code along with and error message in stderr indicating that the specified file does not exist.

Additional Information/Context

No response

CLI version used

aws-cli/2.6.2 Python/3.9.11 Linux/5.13.0-40-generic exe/x86_64.ubuntu.20 prompt/off

Environment details (OS name and version, etc.)

Linux dev 5.13.0-40-generic #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

CyMule avatar May 06 '22 18:05 CyMule

Found the following, which explains the behavior a bit: https://stackoverflow.com/a/49921330/5070770

It'd be great to fix, but it appears to be much more complicated than a simple bug.

kgrimes2 avatar May 06 '22 19:05 kgrimes2

Thanks @kgrimes2 for sharing that link. I think the S3 behavior described there explains the CLI return code. In the example provided, the API runs successfully and returns a 200 response which results in a return code of 0. For more information on return codes in the CLI see: https://docs.aws.amazon.com/cli/latest/topic/return-codes.html.

tim-finnigan avatar May 06 '22 21:05 tim-finnigan

Thanks for your patience. As suggested earlier, this issue is complicated due to how delete operations work in S3. I don't think the command behavior can be changed, but maybe a note on this could be added here for clarification: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/rm.html. Otherwise you can use head-object or ls commands to verify whether an object exists before or after attempting to delete it.

tim-finnigan avatar Aug 27 '24 18:08 tim-finnigan