papis / papis-rofi

Rofi based papis interface
14 stars 5 forks source link

Crash if an invalid folder is passed (list index out of range) #9

Open melhindi opened 1 year ago

melhindi commented 1 year ago

I just installed papis and papis rofi and tried to run it without doing anything else. When I open papis rofi and then press Alt-u to browse the librar, I get the following error:

~ papis rofi  
INFO:db:cache:Indexing library, this might take a while...
Traceback (most recent call last):
  File "/usr/bin/papis", line 33, in <module>
    sys.exit(load_entry_point('papis==0.12', 'console_scripts', 'papis')())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/papis_rofi/main.py", line 218, in main
    return Gui().main(documents)
  File "/usr/lib/python3.10/site-packages/papis_rofi/main.py", line 186, in main
    browse(self.documents[i])
IndexError: list index out of range

This is how my config looks like (default config after installing papis):

[papers]
dir = ~/Documents/papers

[settings]
default-library = papers

It turns out that I have a custom folder with the exact same name that is not a papis library. The same behavior is observable for an empty folder. The papis cli tool handles this gracefully, ie., it does not crash. However, papis-rofi crashes as shown above. I guess simply a check for a valid papis library is missing here?

Etn40ff commented 1 year ago

I can reproduce this with my setup so I doubt it is due to your custom folder. I'll have a look at it.

Etn40ff commented 1 year ago

It looks like the issue is that self.window.select returns [-1] when there are no documents

Etn40ff commented 1 year ago

This should be fixed in latest master branch. Could you test it?

melhindi commented 1 year ago

I just tried: 1) Remove my previous package based installation 2) Create a new tmp folder and a python3 venv 3) Activate the venv and clone the repository 4) run pip3 install . inside the repo (this also downloads the papis dependency) 5) run papis rofi

And can confirm that the program does not crash anymore. However, it simply quits. In case it is easy to add, it would be great to see an info message, like "No libraries found" or so. But I am fine with closing the issue since it addresses the previously reported error message.