Use file extension to select config file parser
This patch makes Dotbot provide better error messages when parsing JSON files.
This commit is contained in:
parent
c48d16cbce
commit
47ad7f4d3b
1 changed files with 6 additions and 9 deletions
|
@ -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:
|
||||
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)
|
||||
print ext
|
||||
if ext == '.json':
|
||||
data = json.load(fin)
|
||||
except Exception:
|
||||
raise e
|
||||
else:
|
||||
data = yaml.safe_load(fin)
|
||||
return data
|
||||
except Exception as e:
|
||||
msg = string.indent_lines(str(e))
|
||||
|
|
Loading…
Reference in a new issue