Browse Source

Merge pull request #226 from patacrep/fail_on_contentlist

Consider 'error' on contentlist exception
pull/230/head
oliverpool 9 years ago
committed by GitHub
parent
commit
9a947b15a7
  1. 3
      NEWS.md
  2. 10
      patacrep/content/__init__.py
  3. 1
      patacrep/data/templates/songbook_model.yml

3
NEWS.md

@ -3,6 +3,9 @@
* Bugfixes
* The capo directive of the Chordpro files is now considered [#224](https://github.com/patacrep/patacrep/pull/224)
* Chordpro files don't need to end with a trailing line [#223](https://github.com/patacrep/patacrep/pull/223)
* Enhancements
* Error management
* The 'error' option is considered for contentlist errors (incorrect syntax for instance) [#226](https://github.com/patacrep/patacrep/pull/226)
# patacrep 5.0.0

10
patacrep/content/__init__.py

@ -185,6 +185,12 @@ class ContentList:
continue
yield from item.iter_errors()
def has_errors(self):
"""Return `True` iff errors has been found."""
for _ in self.iter_errors():
return True
return False
class EmptyContentList(ContentList):
"""Empty content list: contain only errors."""
def __init__(self, *, errors):
@ -281,4 +287,8 @@ def process_content(content, config=None):
contentlist.append_error(error)
else:
contentlist.append_error(ContentError(str(elem), "Unknown content type."))
if contentlist.has_errors() and config['_error'] in ("failonsong", "failonbook"):
raise ContentError(
"Error while parsing the 'content' section of the songbook. Stopping as requested."
)
return contentlist

1
patacrep/data/templates/songbook_model.yml

@ -99,6 +99,7 @@ schema:
- type: //nil
default:
en:
_error: "fix"
_datadir: [] # For test reasons
book:
lang: en

Loading…
Cancel
Save