Adding back "wrapped" exceptions in Refresh/Transport errors.
diff --git a/google/auth/_default.py b/google/auth/_default.py
index 06f52bb..5410a4c 100644
--- a/google/auth/_default.py
+++ b/google/auth/_default.py
@@ -71,7 +71,8 @@
info = json.load(file_obj)
except ValueError as caught_exc:
new_exc = exceptions.DefaultCredentialsError(
- 'File {} is not a valid json file.'.format(filename))
+ 'File {} is not a valid json file.'.format(filename),
+ caught_exc)
six.raise_from(new_exc, caught_exc)
# The type key should indicate that the file is either a service account
@@ -84,9 +85,9 @@
try:
credentials = _cloud_sdk.load_authorized_user_credentials(info)
except ValueError as caught_exc:
- new_exc = exceptions.DefaultCredentialsError(
- 'Failed to load authorized user credentials from {}'.format(
- filename))
+ msg = 'Failed to load authorized user credentials from {}'.format(
+ filename)
+ new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
# Authorized user credentials do not contain the project ID.
return credentials, None
@@ -98,9 +99,9 @@
credentials = (
service_account.Credentials.from_service_account_info(info))
except ValueError as caught_exc:
- new_exc = exceptions.DefaultCredentialsError(
- 'Failed to load service account credentials from {}'.format(
- filename))
+ msg = 'Failed to load service account credentials from {}'.format(
+ filename)
+ new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
return credentials, info.get('project_id')
diff --git a/google/auth/compute_engine/credentials.py b/google/auth/compute_engine/credentials.py
index cbc7cf4..3841df2 100644
--- a/google/auth/compute_engine/credentials.py
+++ b/google/auth/compute_engine/credentials.py
@@ -92,7 +92,7 @@
request,
service_account=self._service_account_email)
except exceptions.TransportError as caught_exc:
- new_exc = exceptions.RefreshError()
+ new_exc = exceptions.RefreshError(caught_exc)
six.raise_from(new_exc, caught_exc)
@property
diff --git a/google/auth/transport/_http_client.py b/google/auth/transport/_http_client.py
index 35b1005..08b1ab6 100644
--- a/google/auth/transport/_http_client.py
+++ b/google/auth/transport/_http_client.py
@@ -106,7 +106,7 @@
return Response(response)
except (http_client.HTTPException, socket.error) as caught_exc:
- new_exc = exceptions.TransportError()
+ new_exc = exceptions.TransportError(caught_exc)
six.raise_from(new_exc, caught_exc)
finally:
diff --git a/google/auth/transport/requests.py b/google/auth/transport/requests.py
index 66ff0d3..a49d3de 100644
--- a/google/auth/transport/requests.py
+++ b/google/auth/transport/requests.py
@@ -118,7 +118,7 @@
**kwargs)
return _Response(response)
except requests.exceptions.RequestException as caught_exc:
- new_exc = exceptions.TransportError()
+ new_exc = exceptions.TransportError(caught_exc)
six.raise_from(new_exc, caught_exc)
diff --git a/google/auth/transport/urllib3.py b/google/auth/transport/urllib3.py
index ec20fb6..37eb317 100644
--- a/google/auth/transport/urllib3.py
+++ b/google/auth/transport/urllib3.py
@@ -133,7 +133,7 @@
method, url, body=body, headers=headers, **kwargs)
return _Response(response)
except urllib3.exceptions.HTTPError as caught_exc:
- new_exc = exceptions.TransportError()
+ new_exc = exceptions.TransportError(caught_exc)
six.raise_from(new_exc, caught_exc)
diff --git a/tests/compute_engine/test_credentials.py b/tests/compute_engine/test_credentials.py
index c78511b..ae2597d 100644
--- a/tests/compute_engine/test_credentials.py
+++ b/tests/compute_engine/test_credentials.py
@@ -75,9 +75,11 @@
def test_refresh_error(self, get):
get.side_effect = exceptions.TransportError('http error')
- with pytest.raises(exceptions.RefreshError):
+ with pytest.raises(exceptions.RefreshError) as excinfo:
self.credentials.refresh(None)
+ assert excinfo.match(r'http error')
+
@mock.patch('google.auth.compute_engine._metadata.get', autospec=True)
def test_before_request_refreshes(self, get):
get.side_effect = [{
diff --git a/tests/test__default.py b/tests/test__default.py
index 090cea6..2df8a44 100644
--- a/tests/test__default.py
+++ b/tests/test__default.py
@@ -85,6 +85,7 @@
_default._load_credentials_from_file(str(filename))
assert excinfo.match(r'Failed to load authorized user')
+ assert excinfo.match(r'missing fields')
def test__load_credentials_from_file_service_account():
@@ -102,6 +103,7 @@
_default._load_credentials_from_file(str(filename))
assert excinfo.match(r'Failed to load service account')
+ assert excinfo.match(r'missing fields')
@mock.patch.dict(os.environ, {}, clear=True)