From c4ddefd45a3d6d5e651d7979d156a1383c7744be Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Sun, 4 Jun 2017 20:03:37 +0200 Subject: [PATCH] catch error in root settings --- prosopopee/prosopopee.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index f0c06d8..18286fe 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -273,7 +273,14 @@ def get_settings(): error(Path("settings.yaml").exists(), "I can't find a " "settings.yaml in the current working directory") - settings = yaml.safe_load(open("settings.yaml", "r")) + try: + settings = yaml.safe_load(open("settings.yaml", "r")) + except yaml.YAMLError, exc: + if hasattr(exc, 'problem_mark'): + mark = exc.problem_mark + error(False, "There are something wrong in settings.yaml line %s" % (mark.line+1)) + else: + erro(False, "There are omething wrong in settings.yaml") error(isinstance(settings, dict), "Your settings.yaml should be a dict") @@ -358,7 +365,7 @@ def process_directory(gallery_name, settings, parent_templates, parent_gallery_p gallery_path = gallery_name try: - gallery_settings = yaml.load(open(Path(".").joinpath(gallery_path, "settings.yaml").abspath(), "r")) + gallery_settings = yaml.safe_load(open(Path(".").joinpath(gallery_path, "settings.yaml").abspath(), "r")) except yaml.YAMLError, exc: if hasattr(exc, 'problem_mark'): mark = exc.problem_mark