From a4d063b7014383365c739f5b7fb3c53a0e0a2344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20T=C3=A4nzer?= Date: Thu, 7 Dec 2023 15:35:07 +0100 Subject: [PATCH] [issue-773] shorten output of FileNotFoundError when called via the CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Armin Tänzer --- src/spdx_tools/spdx/clitools/pyspdxtools.py | 4 ++++ tests/spdx/test_cli.py | 1 + 2 files changed, 5 insertions(+) diff --git a/src/spdx_tools/spdx/clitools/pyspdxtools.py b/src/spdx_tools/spdx/clitools/pyspdxtools.py index 8603b8401..6a46b0d84 100644 --- a/src/spdx_tools/spdx/clitools/pyspdxtools.py +++ b/src/spdx_tools/spdx/clitools/pyspdxtools.py @@ -113,6 +113,10 @@ def main(infile: str, outfile: str, version: str, novalidation: bool, graph: boo logging.error(log_string) sys.exit(1) + except FileNotFoundError as err: + logging.error(f"{err.strerror}: {err.filename}") + sys.exit(1) + if __name__ == "__main__": main() diff --git a/tests/spdx/test_cli.py b/tests/spdx/test_cli.py index 6fcbe3733..0019cf3a3 100644 --- a/tests/spdx/test_cli.py +++ b/tests/spdx/test_cli.py @@ -42,6 +42,7 @@ def test_cli_with_system_exit_code_0(options): "data/invalid/spdx-trivy-vmware_log-intelligence-fluentd-sha256_086af034f561f343f633be9d9f9e95f65ae6c61b8ddb2c6755ef5bb25b40f53a.json", # noqa: E501 ), ), + ("-i", "non_existent_file.spdx"), ], ) def test_cli_with_system_exit_code_1(options):