aboutsummaryrefslogtreecommitdiffstats
path: root/config_file/parsers/json_parser.py
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-02-09 13:54:09 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-02-09 13:54:09 -0600
commit5fa867ba5a2e0927e9b87a8228989357924623d2 (patch)
tree76f298bf573a7d8839562e910874688c992029b7 /config_file/parsers/json_parser.py
parentAdd requests to tox (diff)
downloadconfig-file-5fa867ba5a2e0927e9b87a8228989357924623d2.zip
Allow a default value for the get() method
Diffstat (limited to 'config_file/parsers/json_parser.py')
-rw-r--r--config_file/parsers/json_parser.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/config_file/parsers/json_parser.py b/config_file/parsers/json_parser.py
index 8e4617b..9b8e93c 100644
--- a/config_file/parsers/json_parser.py
+++ b/config_file/parsers/json_parser.py
@@ -76,8 +76,17 @@ class JsonParser(BaseParser):
elif "." in key:
split_keys = split_on_dot(key)
result = self.parsed_content
- for key in split_keys:
- result = result[key]
+
+ # Used so we can more precisely specify what key is causing the error.
+ key_for_error = None
+ try:
+ for key in split_keys:
+ key_for_error = key
+ result = result[key]
+ except TypeError:
+ raise ParsingError(
+ f"Cannot get {key} because {key_for_error} is not subscriptable."
+ )
else:
result = self.parsed_content[key]