HorlogeSkynet / archey4

:computer: Maintained fork of the original Archey (Linux) system tool
https://git.io/archey4
GNU General Public License v3.0
291 stars 37 forks source link

[DISK] Fixes `df` output parsing when FS column contains whitespaces #102

Closed lourinaldi closed 2 years ago

lourinaldi commented 3 years ago

use the float() method to avoid invalid literal for int() with base 10

Description

The Python ValueError: invalid literal for int() with base 10 error is raised when you try to convert a string value that is not formatted as an integer.

To solve this problem, you can use the float() method to convert a floating-point number in a string to an integer. Then, you can use int() to convert your number to an integer.

Reason and / or context

Traceback (most recent call last):
  File "/opt/homebrew/bin/archey", line 33, in <module>
    sys.exit(load_entry_point('archey4==4.13.1', 'console_scripts', 'archey')())
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/__main__.py", line 168, in main
    for entry_instance in mapper(_entry_instantiator, available_entries):
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 608, in result_iterator
    yield fs.pop().result()
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 438, in result
    return self.__get_result()
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/__main__.py", line 144, in _entry_instantiator
    return Entries[entry.pop('type')].value(
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/entries/disk.py", line 18, in __init__
    self._disk_dict = self._get_df_output_dict()
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/entries/disk.py", line 133, in _get_df_output_dict
    'total_blocks': int(columns[1])
ValueError: invalid literal for int() with base 10: 'Us.app/Wrapper'

How has this been tested ?

Python 3.9.7 on MacOS 11.6

Types of changes :

Checklist :

HorlogeSkynet commented 3 years ago

Hey, thanks for opening this up. From your traceback, I don't think your patch would fix anything : "ValueError: invalid literal for int() with base 10: 'Us.app/Wrapper'". There seems to be a problem related to the parsing of df output, as encountered on Windows. Could you paste here the output of df -P -k on your system ?

Thanks, bye 👋

lourinaldi commented 3 years ago

Hey, thanks for opening this up. From your traceback, I don't think your patch would fix anything : "ValueError: invalid literal for int() with base 10: 'Us.app/Wrapper'". There seems to be a problem related to the parsing of df output, as encountered on Windows. Could you paste here the output of df -P -k on your system ?

Thanks, bye 👋

So it looks like it didn't like whitespace in the Volume name under the "Filesystem" column of df's output (/Applications/Among Us.app/Wrapper).

HorlogeSkynet commented 3 years ago

Indeed, the parsing is currently very naive, as based on whitespaces. It worked well on *NIX and derivatives as the filesystem column was not supposed to contain any whitespace. I'll try to fix this without aiming for proper Windows support (as originally planned), as you are already concerned on macOS. Cheers

HorlogeSkynet commented 3 years ago

@lourinaldi please check the updated patch and tell me whether it suits you. If you can provide a "real" example in unit tests, it would be great. Bye :wave: