s3cmd
s3cmd copied to clipboard
`du` throws error when invoked with no buckets
Hello there.
I removed all my buckets and then run s3cmd du
. It showed me 0 Total
, but also showed this:
$ s3cmd du
------------
0 Total
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
An unexpected error has occurred.
Please try reproducing the error using
the latest s3cmd code from the git master
branch found at:
https://github.com/s3tools/s3cmd
and have a look at the known issues list:
https://github.com/s3tools/s3cmd/wiki/Common-known-issues-and-their-solutions-(FAQ)
If the error persists, please report the
following lines (removing any private
info as necessary) to:
[email protected]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Invoked as: /usr/bin/s3cmd du
Problem: <class 'UnboundLocalError: local variable 'size' referenced before assignment
S3cmd: 2.3.0
python: 3.6.8 (default, Nov 10 2022, 12:32:59)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-15.0.1)]
environment LANG=C.UTF-8
Traceback (most recent call last):
File "/usr/bin/s3cmd", line 3286, in <module>
rc = main()
File "/usr/bin/s3cmd", line 3183, in main
rc = cmd_func(args)
File "/usr/bin/s3cmd", line 104, in cmd_du
subcmd_bucket_usage_all(s3)
File "/usr/bin/s3cmd", line 124, in subcmd_bucket_usage_all
return size
UnboundLocalError: local variable 'size' referenced before assignment
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
An unexpected error has occurred.
Please try reproducing the error using
the latest s3cmd code from the git master
branch found at:
https://github.com/s3tools/s3cmd
and have a look at the known issues list:
https://github.com/s3tools/s3cmd/wiki/Common-known-issues-and-their-solutions-(FAQ)
If the error persists, please report the
above lines (removing any private
info as necessary) to:
[email protected]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I'm not that good at Python, but I believe that it's due to fact that size
variable is first assigned in the loop which does not cycle, because the response is empty:
https://github.com/s3tools/s3cmd/blob/6f3e1baa667da53422f60bd941112e1f3a07662c/s3cmd#L107-L124
It looks like the function should not return size
at all and should return buckets_size
instead 🤔