From ebaa13f2af221912407d23c021a8423dd2c1932b Mon Sep 17 00:00:00 2001 From: mataotao Date: Fri, 26 Jul 2024 16:51:04 +0800 Subject: [PATCH] Add exception handling to os.remove 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):