Skip to content

Commit

Permalink
make errors more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
you-n-g committed Jul 21, 2020
1 parent 32bb23d commit 0eb6f36
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ This package is under development. We will release it soon in the future.

# Installation

[fzf](https://github.com/junegunn/fzf) is required
<!-- [fzf](https://github.com/junegunn/fzf) is required -->
```shell
pip install wan # TODO: upload this to pip source
```

## config

Expand Down
2 changes: 1 addition & 1 deletion wan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def wait(self, pid=None, message=None, idle=False, patience=20, sleep=3):
if pid is None:
pid = get_pid_via_fzf()
if pid is None:
logger.info('No process selected')
logger.info('No process selected, You can used --pid to specify the process')
return

process_info = self._get_process_info(pid)
Expand Down
8 changes: 7 additions & 1 deletion wan/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
from iterfzf import iterfzf
from loguru import logger


def iter_ps():
Expand All @@ -14,7 +15,12 @@ def get_pid_from_line(line):


def get_pid_via_fzf(exact=True):
return get_pid_from_line(iterfzf(iter_ps(), multi=False, exact=exact))
try:
selected_line = iterfzf(iter_ps(), multi=False, exact=exact)
except PermissionError as e:
logger.error(f'Please make {e.filename} executable(e.g `chmod a+x {e.filename}`).')
return None
return get_pid_from_line(selected_line)


if __name__ == "__main__":
Expand Down

0 comments on commit 0eb6f36

Please sign in to comment.