From 957cb756c8dcaf700154542f09870b0991918c78 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Tue, 9 Feb 2016 18:04:16 +0100 Subject: [PATCH] Improve Rx exception messages --- patacrep/build.py | 10 ++++++++-- patacrep/errors.py | 2 +- patacrep/templates.py | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index f6b176c2..f123228d 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -48,7 +48,7 @@ class Songbook: try: utils.validate_yaml_schema(raw_songbook, schema) except errors.SchemaError as exception: - exception.message = "The songbook file '{}' is not valid".format(basename) + exception.message = "The songbook file '{}' is not valid\n".format(basename) raise exception self._raw_config = raw_songbook @@ -89,7 +89,13 @@ class Songbook: self._config['book']['lang'], self._config['book']['encoding'], ) - self._config['_template'] = renderer.get_all_variables(self._config.get('template', {})) + + try: + self._config['_template'] = renderer.get_all_variables(self._config.get('template', {})) + except errors.SchemaError as exception: + exception.message = "The songbook file '{}' is not valid\n{}".format( + self.basename, exception.message) + raise exception self._config['_compiled_authwords'] = authors.compile_authwords( copy.deepcopy(self._config['authors']) diff --git a/patacrep/errors.py b/patacrep/errors.py index a72fac2f..5bb3896d 100644 --- a/patacrep/errors.py +++ b/patacrep/errors.py @@ -17,7 +17,7 @@ class SchemaError(SongbookError): def __str__(self): if self.rx_exception: - return self.message + "\n" + str(self.rx_exception) + return self.message + str(self.rx_exception) else: return self.message diff --git a/patacrep/templates.py b/patacrep/templates.py index 0fbf7115..b47dd683 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -173,8 +173,7 @@ class TexBookRenderer(Renderer): try: variables[templatename] = self._get_variables(param, template_config) except errors.SchemaError as exception: - exception.message = "The songbook file is not valid\n" - exception.message += "'template' > '{}' >".format(templatename) + exception.message += "'template' > '{}' > ".format(templatename) raise exception return variables