diff --git a/file_scripts/fzf.py b/file_scripts/fzf.py index 905a896..9c9201b 100644 --- a/file_scripts/fzf.py +++ b/file_scripts/fzf.py @@ -30,14 +30,15 @@ class FZFError(Exception): """ - def __init__(self, exit_code): + def __init__(self, exit_code, message): """ :type exit_code: int """ self.exit_code = exit_code + self.message = message def __repr__(self): - return f"FZFError({self.exit_code})" + return f"FZFError({self.exit_code}, {self.message})" def __str__(self): return str(self.__repr__()) @@ -58,6 +59,6 @@ def select_file_with_fzf(files): try: output.check_returncode() except subprocess.CalledProcessError as e: - raise FZFError(e.returncode) from e + raise FZFError(e.returncode, e.stderr) from e else: return Path(output.stdout.decode(LOCALE).strip("\x00")) diff --git a/tests/test_fzf.py b/tests/test_fzf.py index d04975b..7f89a52 100644 --- a/tests/test_fzf.py +++ b/tests/test_fzf.py @@ -34,9 +34,7 @@ class TestFZFErrors(unittest.TestCase): self.mocked_run = self.patched_subprocess.start() def test_raises_error(self): - self.mocked_run.return_value.check_returncode.side_effect = ( - subprocess.CalledProcessError(1, "hi") - ) + self.mocked_run.side_effect = subprocess.CalledProcessError(1, "hi") with self.assertRaises(fzf.FZFError): fzf.select_file_with_fzf(b"test") @@ -47,6 +45,6 @@ class TestFZFErrors(unittest.TestCase): class TestFZFErrorClass(unittest.TestCase): def test_class_repr(self): - f = fzf.FZFError(1) + f = fzf.FZFError(1, "error") f str(f)