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

Negative difference of sizes in archive gives ValueError: math domain error #1650

Closed
2 tasks done
jetchirag opened this issue Mar 14, 2023 · 4 comments · Fixed by #1651
Closed
2 tasks done

Negative difference of sizes in archive gives ValueError: math domain error #1650

jetchirag opened this issue Mar 14, 2023 · 4 comments · Fixed by #1651
Assignees
Labels
good first issue Simple change to start learning code base help wanted This issue is available, comment if you want to fix it type:bug Something doesn't work as intended

Comments

@jetchirag
Copy link
Contributor

Description

Steps to reproduce:

  1. I created a source with a single file and started a backup
  2. Added a file and created another archive
  3. Remove the previous file and started last backup

When I see the diff of first two backups (in which I added a file), it works fine but when I try to view the diff for last two archives, it gives this error:

Traceback (most recent call last):
  File "/Users/xxx/Projects/vorta/vorta/src/vorta/views/diff_result.py", line 776, in data
    return pretty_bytes(item.data.changed_size)
  File "/Users/xxx/Projects/vorta/vorta/src/vorta/utils.py", line 290, in pretty_bytes
    n = find_best_unit_for_size(size, metric=metric, precision=precision)
  File "/Users/xxx/Projects/vorta/vorta/src/vorta/utils.py", line 269, in find_best_unit_for_size
    n = math.floor(math.log(size * 10**precision, power))
ValueError: math domain error

I traced the error down to

elif column == 2:
return pretty_bytes(item.data.changed_size)
else:
# size
return pretty_bytes(item.data.size)

value of item.data.changed_size and item.data.size is in negative because log can't take negative value

n = math.floor(math.log(size * 10**precision, power))

Suggested fix:

n = math.floor(math.log(abs(size) * 10**precision, power))

It would still calculate the best unit and display +/- as per size. I'm not sure if I'm missing something. If this is a bug, please assign this to me so I can open a PR.

Reproduction

  • I tried to reproduce the issue.
  • I was able to reproduce the issue.

OS

macOS 12.2.1

Version of Vorta

0.8.10 / master branch

What did you install Vorta with?

Pip

Version of Borg

No response

Logs

Traceback (most recent call last):
  File "/Users/xxx/Projects/vorta/vorta/src/vorta/views/diff_result.py", line 776, in data
    return pretty_bytes(item.data.changed_size)
  File "/Users/xxx/Projects/vorta/vorta/src/vorta/utils.py", line 290, in pretty_bytes
    n = find_best_unit_for_size(size, metric=metric, precision=precision)
  File "/Users/xxx/Projects/vorta/vorta/src/vorta/utils.py", line 269, in find_best_unit_for_size
    n = math.floor(math.log(size * 10**precision, power))
ValueError: math domain error
@m3nu m3nu added type:bug Something doesn't work as intended good first issue Simple change to start learning code base help wanted This issue is available, comment if you want to fix it labels Mar 14, 2023
@jetchirag
Copy link
Contributor Author

@m3nu @real-yfprojects Can you assign it to me if you have verified the bug?

@real-yfprojects
Copy link
Collaborator

I noticed that one too but somehow forgot to fix it. It was introduced with #1598.

@jetchirag
Copy link
Contributor Author

I've opened a PR with my preferred fix.

@real-yfprojects
Copy link
Collaborator

Thanks. Btw we get a notification for the PR too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Simple change to start learning code base help wanted This issue is available, comment if you want to fix it type:bug Something doesn't work as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants