Skip to content

Commit

Permalink
fix: wrap tarfile with error handling
Browse files Browse the repository at this point in the history
- ensure return to cwd after tarring
  • Loading branch information
18alantom committed Jan 18, 2024
1 parent 0e2e8b4 commit 30f301e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 30f301e

Please sign in to comment.