From d991218138d53f6d30d1ef816cf9044867185bc2 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 5 Jun 2023 17:03:33 -0700 Subject: [PATCH] Raise error when invalid requirements are parsed Fixes: #364 Signed-off-by: Abhijeet Kasurde --- src/ansible_builder/_target_scripts/introspect.py | 3 ++- test/unit/test_introspect.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ansible_builder/_target_scripts/introspect.py b/src/ansible_builder/_target_scripts/introspect.py index e41a6819..a132ea81 100644 --- a/src/ansible_builder/_target_scripts/introspect.py +++ b/src/ansible_builder/_target_scripts/introspect.py @@ -344,7 +344,8 @@ def sanitize_requirements(collection_py_reqs): consolidated.append(req) seen_pkgs.add(req.name) except Exception as e: - logger.warning('Warning: failed to parse requirements from %s, error: %s', collection, e) + logger.error('Failed to parse requirements from %s, error: %s', collection, e) + sys.exit(1) # removal of unwanted packages sanitized = [] diff --git a/test/unit/test_introspect.py b/test/unit/test_introspect.py index 62dcc494..f91f0dc6 100644 --- a/test/unit/test_introspect.py +++ b/test/unit/test_introspect.py @@ -67,3 +67,9 @@ def test_parse_args_default_action(): assert parser.user_bindep == user_bindep assert parser.write_pip == write_pip assert parser.write_bindep == write_bindep + + +def test_corrupt_python_requirements(): + with pytest.raises(SystemExit) as excinfo: + sanitize_requirements({'test.metadata': ['invalid_package=1']}) + assert excinfo.value.code == 1