From 53cd6e129831e1b9f28f23668f161ac81dafbe75 Mon Sep 17 00:00:00 2001 From: mataotao Date: Fri, 26 Jul 2024 17:22:57 +0800 Subject: [PATCH] Add exception handling to os.remove in the remove-asset-by_pathfang method of the avocado/utilities/asset.py file Signed-off-by: mataotao --- avocado/utils/asset.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/avocado/utils/asset.py b/avocado/utils/asset.py index 33758ccda0..27326d9510 100644 --- a/avocado/utils/asset.py +++ b/avocado/utils/asset.py @@ -684,9 +684,14 @@ def remove_asset_by_path(cls, asset_path): :param asset_path: full path of the asset file. """ - os.remove(asset_path) - filename = f"{asset_path}-CHECKSUM" - os.remove(filename) + try: + os.remove(asset_path) + filename = f"{asset_path}-CHECKSUM" + os.remove(filename) + except FileNotFoundError: + LOG.error(f"File not found: {asset_path} or its checksum file.") + except Exception as e: + LOG.error(f"An error occurred while removing files: {e}") @property def urls(self):