From 0ab7bdd6083051f5cb9b9bc687d2a4bbbe5e2e34 Mon Sep 17 00:00:00 2001 From: RussTreadon-NOAA Date: Tue, 17 Sep 2024 18:20:47 +0000 Subject: [PATCH] improve error handling for jedi class tarfile.extractall (#2862) --- ush/python/pygfs/jedi/jedi.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ush/python/pygfs/jedi/jedi.py b/ush/python/pygfs/jedi/jedi.py index b5fdb42c7c..08cfbc02af 100644 --- a/ush/python/pygfs/jedi/jedi.py +++ b/ush/python/pygfs/jedi/jedi.py @@ -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)