idlesign / torrentool

The tool to work with torrent files.

Home Page:https://github.com/idlesign/torrentool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IndexError on creating torrent from an empty file

Lumen-git opened this issue · comments

using the line myTorrent = Torrent.create_from(activeFile) with activeFile = C:/Users/user/Desktop/test/file2.txt returns:

File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torrentool\torrent.py", line 410, in create_from
info['length'] = target_files[0][1]
IndexError: list index out of range

Unfortunatelly I do not use Windows, and can be little of help.
First check the supplied path is correct (I expect to see backslashes on Windows ).
To investigate it further you may want to set a breakpoint on line 410 and see what's in target_files.

Windows can recognize either slash in a path. Running through the debugger, target_files becomes an empty list by the time the program hits line 357 in torrent.py

Check whether file is empty. Empty files are skipped.

That'd be it. What's the move for not having it crash the whole program on an empty file? A try/except?

We probably need to handle IndexError on line 410.

There're two ways:

  1. Just ignore it. But that would probably produce an invalid torrent file (we'll need to check that using come torrent client, e.g. Transmission).
  2. Wrap it into TorrentError with a more user friendly description, like "Unable to create a torrent for empty file."

The 2nd seems to me more appropriate. If so, yes, try/except is to be used.

Since 1.1.0 TorrentError is raised with a more proper description.

Considered closed.
Feel free to reopen if required.