Skip to content

Commit

Permalink
wrap: Use OSError instead of URLError for exception handling
Browse files Browse the repository at this point in the history
URLError is a subclass of OSError and intermittent server errors can
manifest as OSError while reading instead of a URLError while
establishing a connection, which will cause the fallback url to be
ignored:

```
Looking for a fallback subproject for the dependency gudev-1.0
Downloading libgudev source from https://gitlab.gnome.org/GNOME/libgudev/-/archive/238/libgudev-238.tar.bz2
HTTP Error 404: Not Found
WARNING: failed to download with error: could not get https://gitlab.gnome.org/GNOME/libgudev/-/archive/238/libgudev-238.tar.bz2 is the internet available?. Trying after a delay...
HTTP Error 404: Not Found
WARNING: failed to download with error: could not get https://gitlab.gnome.org/GNOME/libgudev/-/archive/238/libgudev-238.tar.bz2 is the internet available?. Trying after a delay...
HTTP Error 404: Not Found
WARNING: failed to download with error: could not get https://gitlab.gnome.org/GNOME/libgudev/-/archive/238/libgudev-238.tar.bz2 is the internet available?. Trying after a delay...
WARNING: failed to download with error: The read operation timed out. Trying after a delay...
WARNING: failed to download with error: The read operation timed out. Trying after a delay...
ERROR: Unhandled python OSError. This is probably not a Meson bug, but an issue with your build environment.
```

(cherry picked from commit 8a202de)
  • Loading branch information
nirbheek authored and eli-schwartz committed Jul 25, 2024
1 parent b1bd200 commit 3ec1fe2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mesonbuild/wrap/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def open_wrapdburl(urlstring: str, allow_insecure: bool = False, have_opt: bool
if has_ssl:
try:
return T.cast('http.client.HTTPResponse', urllib.request.urlopen(urllib.parse.urlunparse(url), timeout=REQ_TIMEOUT))
except urllib.error.URLError as excp:
except OSError as excp:
msg = f'WrapDB connection failed to {urlstring} with error {excp}.'
if isinstance(excp.reason, ssl.SSLCertVerificationError):
if isinstance(excp, urllib.error.URLError) and isinstance(excp.reason, ssl.SSLCertVerificationError):
if allow_insecure:
mlog.warning(f'{msg}\n\n Proceeding without authentication.')
else:
Expand All @@ -95,7 +95,7 @@ def open_wrapdburl(urlstring: str, allow_insecure: bool = False, have_opt: bool
nossl_url = url._replace(scheme='http')
try:
return T.cast('http.client.HTTPResponse', urllib.request.urlopen(urllib.parse.urlunparse(nossl_url), timeout=REQ_TIMEOUT))
except urllib.error.URLError as excp:
except OSError as excp:
raise WrapException(f'WrapDB connection failed to {urlstring} with error {excp}')

def get_releases_data(allow_insecure: bool) -> bytes:
Expand Down Expand Up @@ -704,7 +704,7 @@ def get_data(self, urlstring: str) -> T.Tuple[str, str]:
try:
req = urllib.request.Request(urlstring, headers=headers)
resp = urllib.request.urlopen(req, timeout=REQ_TIMEOUT)
except urllib.error.URLError as e:
except OSError as e:
mlog.log(str(e))
raise WrapException(f'could not get {urlstring} is the internet available?')
with contextlib.closing(resp) as resp, tmpfile as tmpfile:
Expand Down

0 comments on commit 3ec1fe2

Please sign in to comment.