From 5233643a1a43c88d507a6e3f1d1dd2f6f931ddde Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Nov 10 2022 09:59:42 +0000 Subject: cli: suppress traceback when spec file is missing or has wrong type This is "expected", so we should only print the one-line error message and not the traceback. Signed-off-by: Zbigniew Jędrzejewski-Szmek --- diff --git a/rpmautospec/cli.py b/rpmautospec/cli.py index 89c82cb..c662ffc 100644 --- a/rpmautospec/cli.py +++ b/rpmautospec/cli.py @@ -93,15 +93,18 @@ def get_cli_args(args: typing.List[str]) -> argparse.Namespace: @contextlib.contextmanager -def suppress_expected_exceptions(): +def handle_expected_exceptions(): """Suppress tracebacks on common "expected" exceptions""" try: yield except BrokenPipeError: pass + except OSError as e: + # this covers various cases like file not found / has wrong type / access is denied. + sys.exit(str(e)) -@suppress_expected_exceptions() +@handle_expected_exceptions() def main(): locale.setlocale(locale.LC_ALL, "")