Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More error handling for gfile #1667

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions keras_nlp/src/utils/preset_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def get_file(preset, path):
url,
cache_subdir=os.path.join("models", subdir),
)
except tf.errors.NotFoundError as e:
except (tf.errors.PermissionDeniedError, tf.errors.NotFoundError) as e:
raise FileNotFoundError(
f"`{path}` doesn't exist in preset directory `{preset}`.",
) from e
Expand Down Expand Up @@ -227,7 +227,13 @@ def copy_gfile_to_cache(filename, url, cache_subdir):
fpath = os.path.join(cachedir, filename)
if not os.path.exists(fpath):
print_msg(f"Downloading data from {url}")
tf.io.gfile.copy(url, fpath)
try:
tf.io.gfile.copy(url, fpath)
except Exception as e:
# gfile.copy will leave an empty file after an error.
# Work around this bug.
os.remove(fpath)
raise e

return fpath

Expand Down
Loading