From f438f5a4bd5784db2306475434e002a584c61ec1 Mon Sep 17 00:00:00 2001 From: Nathan Naze Date: Sun, 18 Jan 2015 00:07:01 -0500 Subject: [PATCH] Modify invalid exception error to be less cryptic and give more context to the developer. This is to fix my personal debugging experience when trying to debug the fact that I had downloaded the wrong client secret JSON type (not web/installed). --- oauth2client/clientsecrets.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/oauth2client/clientsecrets.py b/oauth2client/clientsecrets.py index b4c6f52..08a1702 100644 --- a/oauth2client/clientsecrets.py +++ b/oauth2client/clientsecrets.py @@ -69,8 +69,18 @@ class InvalidClientSecretsError(Error): def _validate_clientsecrets(obj): - if obj is None or len(obj) != 1: - raise InvalidClientSecretsError('Invalid file format.') + _INVALID_FILE_FORMAT_MSG = ( + 'Invalid file format. See ' + 'https://developers.google.com/api-client-library/' + 'python/guide/aaa_client_secrets') + + if obj is None: + raise InvalidClientSecretsError(_INVALID_FILE_FORMAT_MSG) + if len(obj) != 1: + raise InvalidClientSecretsError( + _INVALID_FILE_FORMAT_MSG + ' ' + 'Expected a JSON object with a single property for a "web" or ' + '"installed" application') client_type = tuple(obj)[0] if client_type not in VALID_CLIENT: raise InvalidClientSecretsError('Unknown client type: %s.' % (client_type,))