boxed / p

MIT License
2 stars 1 forks source link

Corrupted Path causes p to crash #10

Closed CSDUMMI closed 5 years ago

CSDUMMI commented 5 years ago

I move many things into my PATH and forget to remove it, even if the location that points to has been deleted. So I executed p with a deleted location in PATH and I got:

Traceback (most recent call last):
  File "./p", line 63, in <module>
    exit(main(sys.argv))
  File "./p", line 16, in main
    available_commands = find_available_commands()
  File "/p.py", line 59, in find_available_commands
    r.extend(os.listdir(path))
FileNotFoundError: [Errno 2] No such file or directory: <deleted dir>

So a corrupted PATH and you can't run p? I will try to implement a catch for this error and ignore a location, that doesn't exist.

boxed commented 5 years ago

Good find!

CSDUMMI commented 5 years ago

I think I fixed this with https://github.com/boxed/p/commit/3c8fd8e69d694582363fbc5bf3158454301b34fe and https://github.com/boxed/p/commit/2050a92a41cf778de5ba44b5733d9d5cfa560d81. I introduced a new function called get_paths(paths=[]), which takes a list of locations and if filters out all those, which do not exist. If paths is empty, get_paths returns a list of all existing locations in PATH. I didn't write a test for this yet, but p doesn't crash anymore.