Skip to content

Commit

Permalink
improve error handling for jedi class tarfile.extractall (NOAA-EMC#2862)
Browse files Browse the repository at this point in the history
  • Loading branch information
RussTreadon-NOAA committed Sep 17, 2024
1 parent bdffc02 commit 0ab7bdd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ush/python/pygfs/jedi/jedi.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,19 @@ def extract_tar(self, task_config: AttrDict, tar_dict) -> Dict[str, Any]:
# extract bias correction files from tar file
for tar_file in tar_dict['copy']:
if ".tar" in tar_file[1]:
with tarfile.open(tar_file[1], "r") as tarball:
tarball.extractall(path=os.path.join(task_config.DATA, 'obs'))
logger.info(f"Extract {tarball.getnames()}")
tarball.close()
try:
with tarfile.open(tar_file[1], "r") as tarball:
tarball.extractall(path=os.path.join(task_config.DATA, 'obs'))
logger.info(f"Extract {tarball.getnames()}")
except tarfile.ReadError as err:
if tarfile.is_tarfile(tarfile[1]):
logger.error(f"FATAL ERROR: {tarfile[1]} could not be read")
raise tarfile.ReadError(f"FATAL ERROR: unable to read {tarfile[1]}")
else:
logger.info()
except tarfile.ExtractError as err:
logger.exception(f"FATAL ERROR: unable to extract from {tarfile[1]}")
raise tarfile.ExtractError("FATAL ERROR: unable to extract from {tarfile[1]}")


@logit(logger)
Expand Down

0 comments on commit 0ab7bdd

Please sign in to comment.