diff --git a/songbook_core/build.py b/songbook_core/build.py index a471f07e..6a4a91d4 100644 --- a/songbook_core/build.py +++ b/songbook_core/build.py @@ -114,10 +114,15 @@ class Songbook(object): content = self.config["content"] self.config["content"] = [] for elem in content: - if isinstance(elem, unicode): + if isinstance(elem, str) or isinstance(elem, unicode): self.config["content"].append(("song", elem)) - else: + elif isinstance(elem, list): self.config["content"].append((elem[0], elem[1])) + else: + raise errors.SBFileError( + "Syntax error: could not decode the content " + "of {0}".format(self.basename) + ) # Ensure self.config['authwords'] contains all entries for (key, value) in DEFAULT_AUTHWORDS.items(): @@ -126,7 +131,7 @@ class Songbook(object): def _parse_songs(self): """Parse content included in songbook.""" - self.contentlist = SongbookContent(self.config['datadir']) + self.contentlist = SongbookContent(self.config['datadir']) self.contentlist.append_list(self.config['content']) def write_tex(self, output): @@ -149,7 +154,7 @@ class Songbook(object): context['filename'] = output.name[:-4] self._set_songs_default(context) - + print(self.contentlist.content) renderer.render_tex(output, context) diff --git a/songbook_core/errors.py b/songbook_core/errors.py index 6b850712..d724ae14 100644 --- a/songbook_core/errors.py +++ b/songbook_core/errors.py @@ -10,6 +10,19 @@ class SongbookError(Exception): """ pass +class SBFileError(SongbookError): + """Error during songbook file decoding""" + + def __init__(self, message=None): + super(SBFileError, self).__init__() + self.message = message + + def __str__(self): + if self.message is None: + return str(self.original) + else: + return self.message + class TemplateError(SongbookError): """Error during template generation"""