Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

du throws error when invoked with no buckets #1298

Closed
igoradamenko opened this issue Dec 27, 2022 · 1 comment
Closed

du throws error when invoked with no buckets #1298

igoradamenko opened this issue Dec 27, 2022 · 1 comment
Milestone

Comments

@igoradamenko
Copy link

igoradamenko commented Dec 27, 2022

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:
   s3tools-bugs@lists.sourceforge.net


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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:
   s3tools-bugs@lists.sourceforge.net
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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:

s3cmd/s3cmd

Lines 107 to 124 in 6f3e1ba

def subcmd_bucket_usage_all(s3):
"""
Returns: sum of bucket sizes as integer
Raises: S3Error
"""
cfg = Config()
response = s3.list_all_buckets()
buckets_size = 0
for bucket in response["list"]:
size = subcmd_bucket_usage(s3, S3Uri("s3://" + bucket["Name"]))
if size != None:
buckets_size += size
total_size, size_coeff = formatSize(buckets_size, cfg.human_readable_sizes)
total_size_str = str(total_size) + size_coeff
output(u"".rjust(12, "-"))
output(u"%s Total" % (total_size_str.ljust(12)))
return size

It looks like the function should not return size at all and should return buckets_size instead 🤔

SaschaDoering added a commit to SaschaDoering/s3cmd that referenced this issue Jul 23, 2024
Return and print size 0 and prevent error message if the bucket list is empty.
@fviard fviard added this to the 2.4.1 milestone Sep 10, 2024
@fviard fviard linked a pull request Sep 10, 2024 that will close this issue
@fviard fviard closed this as completed in 8ce5008 Sep 11, 2024
@fviard
Copy link
Contributor

fviard commented Sep 11, 2024

Fixed with 10aea09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants