From d1590ce18b9ed969b588e61c618f867f7a329675 Mon Sep 17 00:00:00 2001 From: Santiago Santa Date: Mon, 2 Sep 2024 09:19:56 -0500 Subject: [PATCH] fix(engine_dependencies): :white_check_mark: Handle error --- .../driven_adapters/xray_tool/xray_manager_scan.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/devsecops_engine_tools/engine_sca/engine_dependencies/src/infrastructure/driven_adapters/xray_tool/xray_manager_scan.py b/tools/devsecops_engine_tools/engine_sca/engine_dependencies/src/infrastructure/driven_adapters/xray_tool/xray_manager_scan.py index d34e494d..9c2fee30 100644 --- a/tools/devsecops_engine_tools/engine_sca/engine_dependencies/src/infrastructure/driven_adapters/xray_tool/xray_manager_scan.py +++ b/tools/devsecops_engine_tools/engine_sca/engine_dependencies/src/infrastructure/driven_adapters/xray_tool/xray_manager_scan.py @@ -212,12 +212,18 @@ def scan_dependencies(self, prefix, cwd, mode, to_scan): scan_result = json.loads(result.stdout) else: scan_result = {} - file_result = os.path.join(os.getcwd(), "scan_result.json") - with open(file_result, "w") as file: - json.dump(scan_result, file, indent=4) + if any( + word in result.stderr + for word in ["What went wrong", "Caused by"] + ): + logger.error(f"Error executing Xray scan: {result.stderr}") + return None if result.stdout == "null\n": logger.warning(f"Xray scan returned null: {result.stderr}") return None + file_result = os.path.join(os.getcwd(), "scan_result.json") + with open(file_result, "w") as file: + json.dump(scan_result, file, indent=4) return file_result else: logger.error(f"Error executing Xray scan: {result.stderr}")