ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

Traceback on zero-size file #268

Closed sanderjo closed 2 years ago

sanderjo commented 2 years ago

Traceback on zero-size file. Maybe better to have no Traceback, and return None or something like that?

puremagic version 1.14:

sander@haring1:~$ python3 -m pip install puremagic -U
Requirement already up-to-date: puremagic in ./.local/lib/python3.8/site-packages (1.14)

Create file with zero size, and nothing in it:

sander@haring1:~$ touch zero_size.somefile
sander@haring1:~$ ll zero_size.somefile 
-rw-rw-r-- 1 sander sander 0 Mai 26 11:21 zero_size.somefile

puremagic gives Traceback

sander@haring1:~$ python3 -m puremagic zero_size.somefile
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/sander/.local/lib/python3.8/site-packages/puremagic/__main__.py", line 5, in <module>
    command_line_entry()
  File "/home/sander/.local/lib/python3.8/site-packages/puremagic/main.py", line 320, in command_line_entry
    print("'{0}' : {1}".format(fn, from_file(fn, args.mime)))
  File "/home/sander/.local/lib/python3.8/site-packages/puremagic/main.py", line 206, in from_file
    return _magic(head, foot, mime, ext_from_filename(filename))
  File "/home/sander/.local/lib/python3.8/site-packages/puremagic/main.py", line 139, in _magic
    raise ValueError("Input was empty")
ValueError: Input was empty
ahupp commented 2 years ago

This repo is for python-magic, looks like you want to report here: https://github.com/cdgriffith/puremagic