From 30f301e3ffa8a2561160ec740d2d046355905c97 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 18 Jan 2024 18:06:08 +0530 Subject: [PATCH] fix: wrap tarfile with error handling - ensure return to cwd after tarring --- bench/app.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bench/app.py b/bench/app.py index 9321ea00e..0eebdc2eb 100755 --- a/bench/app.py +++ b/bench/app.py @@ -365,11 +365,19 @@ def set_cache(self, compress_artifacts=False) -> bool: click.secho(message) self.prune_app_directory() + + success = False os.chdir(app_path.parent) - with tarfile.open(cache_path, mode) as tar: - tar.add(app_path.name) - os.chdir(cwd) - return True + try: + with tarfile.open(cache_path, mode) as tar: + tar.add(app_path.name) + success = True + except Exception: + log(f"Failed to cache {app_path}", level=3) + success = False + finally: + os.chdir(cwd) + return success def prune_app_directory(self): app_path = self.get_app_path()