From 79bf664b3c28e108dd613c18c3d4b60e5fa97f6a Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Wed, 13 Jan 2016 09:46:35 +0100 Subject: [PATCH] Better handle content error --- patacrep/content/__init__.py | 20 +++++++++++--------- test/test_content/invalid.control | 1 + test/test_content/invalid.source | 4 ++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test/test_content/invalid.control create mode 100644 test/test_content/invalid.source diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index 438efe52..26e67080 100755 --- a/patacrep/content/__init__.py +++ b/patacrep/content/__init__.py @@ -238,12 +238,11 @@ def validate_parser_argument(raw_schema): try: schema.validate(argument) except Rx.SchemaMismatch as exception: - msg = 'Invalid `{}` syntax:\n---\n{}---\n{}'.format( - keyword, + msg = 'Invalid syntax:\n---\n{}---\n{}'.format( yaml.dump({keyword: argument}, default_flow_style=False), str(exception) ) - raise SBFileError(msg) + raise ContentError(keyword, msg) return parse(keyword, argument=argument, config=config) return wrapped return wrap @@ -272,11 +271,14 @@ def process_content(content, config=None): if keyword not in plugins: contentlist.append_error(ContentError(keyword, "Unknown content keyword.")) continue - contentlist.extend(plugins[keyword]( - keyword, - argument=argument, - config=config, - )) + try: + contentlist.extend(plugins[keyword]( + keyword, + argument=argument, + config=config, + )) + except ContentError as error: + contentlist.append_error(error) else: - contentlist.append_error(ContentError(elem, "Unknown content type.")) + contentlist.append_error(ContentError(str(elem), "Unknown content type.")) return contentlist diff --git a/test/test_content/invalid.control b/test/test_content/invalid.control new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/test/test_content/invalid.control @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/test_content/invalid.source b/test/test_content/invalid.source new file mode 100644 index 00000000..7952bf8f --- /dev/null +++ b/test/test_content/invalid.source @@ -0,0 +1,4 @@ +- ["directly", "a", "list"] +- invalid_keyword: Test +- section: + short: Missing name \ No newline at end of file