Browse Source

Better handle content error

pull/190/head
Oliverpool 9 years ago
parent
commit
79bf664b3c
  1. 10
      patacrep/content/__init__.py
  2. 1
      test/test_content/invalid.control
  3. 4
      test/test_content/invalid.source

10
patacrep/content/__init__.py

@ -238,12 +238,11 @@ def validate_parser_argument(raw_schema):
try: try:
schema.validate(argument) schema.validate(argument)
except Rx.SchemaMismatch as exception: except Rx.SchemaMismatch as exception:
msg = 'Invalid `{}` syntax:\n---\n{}---\n{}'.format( msg = 'Invalid syntax:\n---\n{}---\n{}'.format(
keyword,
yaml.dump({keyword: argument}, default_flow_style=False), yaml.dump({keyword: argument}, default_flow_style=False),
str(exception) str(exception)
) )
raise SBFileError(msg) raise ContentError(keyword, msg)
return parse(keyword, argument=argument, config=config) return parse(keyword, argument=argument, config=config)
return wrapped return wrapped
return wrap return wrap
@ -272,11 +271,14 @@ def process_content(content, config=None):
if keyword not in plugins: if keyword not in plugins:
contentlist.append_error(ContentError(keyword, "Unknown content keyword.")) contentlist.append_error(ContentError(keyword, "Unknown content keyword."))
continue continue
try:
contentlist.extend(plugins[keyword]( contentlist.extend(plugins[keyword](
keyword, keyword,
argument=argument, argument=argument,
config=config, config=config,
)) ))
except ContentError as error:
contentlist.append_error(error)
else: else:
contentlist.append_error(ContentError(elem, "Unknown content type.")) contentlist.append_error(ContentError(str(elem), "Unknown content type."))
return contentlist return contentlist

1
test/test_content/invalid.control

@ -0,0 +1 @@
[]

4
test/test_content/invalid.source

@ -0,0 +1,4 @@
- ["directly", "a", "list"]
- invalid_keyword: Test
- section:
short: Missing name
Loading…
Cancel
Save