Browse Source

Shared errors can be turned into dictionaries

pull/176/head
Louis 9 years ago
parent
commit
61721f3425
  1. 9
      patacrep/content/__init__.py
  2. 8
      patacrep/errors.py
  3. 9
      patacrep/latex/__init__.py
  4. 38
      patacrep/songs/errors.py

9
patacrep/content/__init__.py

@ -136,6 +136,15 @@ class ContentError(SharedError):
text += ": " + self.message text += ": " + self.message
return text return text
@property
def __dict__(self):
parent = vars(super())
parent.update({
'keyword': self.keyword,
'message': self.message,
})
return parent
class ContentList: class ContentList:
"""List of content items""" """List of content items"""

8
patacrep/errors.py

@ -110,6 +110,14 @@ class SharedError(SongbookError):
def __str__(self): def __str__(self):
raise NotImplementedError() raise NotImplementedError()
@property
def __dict__(self):
return {
'type': self.__class__.__name__,
'message': str(self),
'full_message': str(self),
}
def notfound(filename, paths, message=None): def notfound(filename, paths, message=None):
"""Return a string saying that file was not found in paths.""" """Return a string saying that file was not found in paths."""
if message is None: if message is None:

9
patacrep/latex/__init__.py

@ -95,6 +95,15 @@ class UnknownLanguage(errors.SharedError):
def __str__(self): def __str__(self):
return self.message return self.message
@property
def __dict__(self):
parent = vars(super())
parent.update({
'original': self.original,
'fallback': self.fallback,
})
return parent
def checklanguage(lang): def checklanguage(lang):
"""Check that `lang` is a known language. """Check that `lang` is a known language.

38
patacrep/songs/errors.py

@ -20,6 +20,17 @@ class SongError(SharedError):
self.song.subpath, 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): class SongSyntaxError(SongError):
"""Syntax error""" """Syntax error"""
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
@ -35,11 +46,29 @@ class SongSyntaxError(SongError):
else: else:
return "{}: {}".format(self._human_song(), self.message) 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): class FileNotFound(SongError):
"""File not found error""" """File not found error"""
def __init__(self, song, filename): def __init__(self, song, filename):
super().__init__(song, "File '{}' not found.".format(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): class SongUnknownLanguage(SongError):
"""Song language is not known.""" """Song language is not known."""
@ -48,3 +77,12 @@ class SongUnknownLanguage(SongError):
super().__init__(song, message) super().__init__(song, message)
self.original = original self.original = original
self.fallback = fallback self.fallback = fallback
@property
def __dict__(self):
parent = vars(super())
parent.update({
'original': self.original,
'fallback': self.fallback,
})
return parent

Loading…
Cancel
Save