From 1322a499117f26e79f977acf9d26eb6e537e190b Mon Sep 17 00:00:00 2001 From: shinriyo Date: Thu, 5 Jul 2018 23:06:15 +0900 Subject: [PATCH] more kindly error When we I mistook `lambda.json` format (ex. like miswrite ,), it tell us what file was mistook. --- lambda_uploader/config.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lambda_uploader/config.py b/lambda_uploader/config.py index c4ef7b4..6cb0356 100644 --- a/lambda_uploader/config.py +++ b/lambda_uploader/config.py @@ -37,6 +37,8 @@ u's3_bucket': None, u's3_key': None, u'runtime': 'python2.7', u'variables': {}, u'subscription': {}, u'tracing': {}} +LAMBDA_JSON = 'lambda.json' + class Config(object): def __init__(self, pth, config_file=None, role=None, variables=None): @@ -186,13 +188,16 @@ def _load_config(self, lambda_file=None): raise Exception("%s not a valid function directory" % self._path) if not lambda_file: - lambda_file = path.join(self._path, 'lambda.json') + lambda_file = path.join(self._path, LAMBDA_JSON) if not path.isfile(lambda_file): raise Exception("%s not a valid configuration file" % lambda_file) with open(lambda_file) as config_file: - self._config = json.load(config_file) + try: + self._config = json.load(config_file) + except json.decoder.JSONDecodeError: + raise Exception("%s not a valid json file" % LAMBDA_JSON) def __getattr__(self, key): if key in self._config: