diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index 1aaf5043..7cdc7061 100755 --- a/patacrep/content/__init__.py +++ b/patacrep/content/__init__.py @@ -136,6 +136,15 @@ class ContentError(SharedError): text += ": " + self.message return text + @property + def __dict__(self): + parent = vars(super()) + parent.update({ + 'keyword': self.keyword, + 'message': self.message, + }) + return parent + class ContentList: """List of content items""" diff --git a/patacrep/errors.py b/patacrep/errors.py index 0db5702b..08eebc6a 100644 --- a/patacrep/errors.py +++ b/patacrep/errors.py @@ -110,6 +110,14 @@ class SharedError(SongbookError): def __str__(self): raise NotImplementedError() + @property + def __dict__(self): + return { + 'type': self.__class__.__name__, + 'message': str(self), + 'full_message': str(self), + } + def notfound(filename, paths, message=None): """Return a string saying that file was not found in paths.""" if message is None: diff --git a/patacrep/latex/__init__.py b/patacrep/latex/__init__.py index f1755186..2aae8813 100644 --- a/patacrep/latex/__init__.py +++ b/patacrep/latex/__init__.py @@ -95,6 +95,15 @@ class UnknownLanguage(errors.SharedError): def __str__(self): return self.message + @property + def __dict__(self): + parent = vars(super()) + parent.update({ + 'original': self.original, + 'fallback': self.fallback, + }) + return parent + def checklanguage(lang): """Check that `lang` is a known language. diff --git a/patacrep/songs/errors.py b/patacrep/songs/errors.py index cee94b65..3a53ba6c 100644 --- a/patacrep/songs/errors.py +++ b/patacrep/songs/errors.py @@ -20,6 +20,17 @@ class SongError(SharedError): self.song.subpath, ) + @property + def __dict__(self): + parent = vars(super()) + parent.update({ + 'datadir': self.song.datadir, + 'subpath': self.song.subpath, + 'message': self.message, + 'full_message': str(self), + }) + return parent + class SongSyntaxError(SongError): """Syntax error""" # pylint: disable=too-few-public-methods @@ -35,11 +46,29 @@ class SongSyntaxError(SongError): else: return "{}: {}".format(self._human_song(), self.message) + @property + def __dict__(self): + parent = vars(super()) + if self.line is not None: + parent.update({ + 'line': self.line, + }) + return parent + class FileNotFound(SongError): """File not found error""" def __init__(self, song, filename): super().__init__(song, "File '{}' not found.".format(filename)) + self.filename = filename + + @property + def __dict__(self): + parent = vars(super()) + parent.update({ + 'filename': self.filename, + }) + return parent class SongUnknownLanguage(SongError): """Song language is not known.""" @@ -48,3 +77,12 @@ class SongUnknownLanguage(SongError): super().__init__(song, message) self.original = original self.fallback = fallback + + @property + def __dict__(self): + parent = vars(super()) + parent.update({ + 'original': self.original, + 'fallback': self.fallback, + }) + return parent