-
Notifications
You must be signed in to change notification settings - Fork 1
Improve download error failures #36
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
Open
ehennestad
wants to merge
2
commits into
main
Choose a base branch
from
codex-improve-error-when-download-fails
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| versions.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import re | ||
| import shutil | ||
| import json | ||
| import ssl | ||
| import urllib.request | ||
| import urllib.error | ||
|
|
||
|
|
@@ -19,6 +20,10 @@ | |
|
|
||
| _remote_schema_cache = {} | ||
|
|
||
|
|
||
| class DownloadError(RuntimeError): | ||
| pass | ||
|
|
||
| class VocabManager: | ||
| def __init__(self, path_vocab_types, path_vocab_properties): | ||
| # TODO handle dev | ||
|
|
@@ -50,11 +55,23 @@ def load_json(file_path): | |
| json_file = json.load(f) | ||
| return json_file | ||
|
|
||
| def _format_download_error(url, path, error): | ||
| if isinstance(error, urllib.error.URLError) and isinstance(error.reason, ssl.SSLCertVerificationError): | ||
| reason = "SSL certificate verification failed. Check your local Python certificate store." | ||
| else: | ||
| reason = str(error) | ||
| return f'Failed to download "{url}" to "{path}": {reason}' | ||
|
Comment on lines
+58
to
+63
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could move "_format_download_error" into DownloadError as a @classmethod, and rename it to something like from_exception, since its responsibility is focused only on producing a clear error message. |
||
|
|
||
| def download_file(url, path): | ||
| try: | ||
| urllib.request.urlretrieve(url, path) | ||
| except (urllib.error.URLError, IOError) as e: | ||
| logging.error(e) | ||
| has_local_fallback = os.path.exists(path) and os.path.getsize(path) > 0 | ||
| message = _format_download_error(url, path, e) | ||
| if has_local_fallback: | ||
| logging.warning(f"{message} Using existing local file instead.") | ||
| return | ||
| raise DownloadError(message) from e | ||
|
|
||
| def clone_central(refetch:bool=False): | ||
| if refetch and os.path.exists("sources"): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could improve this by adding an init method that accepts url and path as part of the exception, instead of passing and handling them separately throughout the code.