From 47ad7f4d3b69315e25ae96099fe73b4d9cd7666e Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Wed, 13 Jan 2016 13:46:41 -0500 Subject: [PATCH] Use file extension to select config file parser This patch makes Dotbot provide better error messages when parsing JSON files. --- dotbot/config.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/dotbot/config.py b/dotbot/config.py index a9aafa0..39ab60b 100644 --- a/dotbot/config.py +++ b/dotbot/config.py @@ -1,5 +1,6 @@ import yaml import json +import os.path from .util import string class ConfigReader(object): @@ -8,17 +9,13 @@ class ConfigReader(object): def _read(self, config_file_path): try: + _, ext = os.path.splitext(config_file_path) with open(config_file_path) as fin: - try: + print ext + if ext == '.json': + data = json.load(fin) + else: data = yaml.safe_load(fin) - except Exception as e: - # try falling back to JSON, but return original exception - # if that fails too - try: - fin.seek(0) - data = json.load(fin) - except Exception: - raise e return data except Exception as e: msg = string.indent_lines(str(e))