Using `six.raise_from` wherever possible.
diff --git a/google/auth/_default.py b/google/auth/_default.py
index 7dac642..06f52bb 100644
--- a/google/auth/_default.py
+++ b/google/auth/_default.py
@@ -22,6 +22,8 @@
import logging
import os
+import six
+
from google.auth import environment_vars
from google.auth import exceptions
import google.auth.transport._http_client
@@ -67,9 +69,10 @@
with io.open(filename, 'r') as file_obj:
try:
info = json.load(file_obj)
- except ValueError as exc:
- raise exceptions.DefaultCredentialsError(
- 'File {} is not a valid json file.'.format(filename), exc)
+ except ValueError as caught_exc:
+ new_exc = exceptions.DefaultCredentialsError(
+ 'File {} is not a valid json file.'.format(filename))
+ six.raise_from(new_exc, caught_exc)
# The type key should indicate that the file is either a service account
# credentials file or an authorized user credentials file.
@@ -80,10 +83,11 @@
try:
credentials = _cloud_sdk.load_authorized_user_credentials(info)
- except ValueError as exc:
- raise exceptions.DefaultCredentialsError(
+ except ValueError as caught_exc:
+ new_exc = exceptions.DefaultCredentialsError(
'Failed to load authorized user credentials from {}'.format(
- filename), exc)
+ filename))
+ six.raise_from(new_exc, caught_exc)
# Authorized user credentials do not contain the project ID.
return credentials, None
@@ -93,10 +97,11 @@
try:
credentials = (
service_account.Credentials.from_service_account_info(info))
- except ValueError as exc:
- raise exceptions.DefaultCredentialsError(
+ except ValueError as caught_exc:
+ new_exc = exceptions.DefaultCredentialsError(
'Failed to load service account credentials from {}'.format(
- filename), exc)
+ filename))
+ six.raise_from(new_exc, caught_exc)
return credentials, info.get('project_id')
else: