mirror of
https://github.com/jchook/ranger-zoxide.git
synced 2025-12-26 18:34:56 +08:00
Clean up error handling
This commit is contained in:
parent
37c59cc701
commit
6a8591807e
1 changed files with 11 additions and 13 deletions
24
__init__.py
24
__init__.py
|
|
@ -33,22 +33,20 @@ class z(ranger.api.commands.Command):
|
|||
|
||||
def query(self, args):
|
||||
try:
|
||||
p = self.fm.execute_command("zoxide query {}".format(" ".join(self.args[1:])),
|
||||
stdout=PIPE
|
||||
)
|
||||
stdout, stderr = p.communicate()
|
||||
zoxide = self.fm.execute_command(f"zoxide query {' '.join(self.args[1:])}",
|
||||
stdout=PIPE
|
||||
)
|
||||
stdout, stderr = zoxide.communicate()
|
||||
|
||||
if not stdout:
|
||||
return None
|
||||
|
||||
if p.returncode == 0:
|
||||
if zoxide.returncode == 0:
|
||||
output = stdout.decode("utf-8").strip()
|
||||
if output:
|
||||
return output.splitlines()
|
||||
else:
|
||||
self.fm.notify("zoxide exited with status {}".format(p.returncode), bad=True)
|
||||
return output.splitlines()
|
||||
elif zoxide.returncode == 1: # nothing found
|
||||
return None
|
||||
elif zoxide.returncode == 130: # user cancelled
|
||||
return None
|
||||
else:
|
||||
output = stderr.decode("utf-8").strip() or "zoxide: unexpected error"
|
||||
output = stderr.decode("utf-8").strip() or f"zoxide: unexpected error (exit code {zoxide.returncode})"
|
||||
self.fm.notify(output, bad=True)
|
||||
except Exception as e:
|
||||
self.fm.notify(e, bad=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue