Added error type back the right way, shorter error messages.

This commit is contained in:
Mattias Põldaru 2012-03-09 08:19:39 +02:00
parent 2b28482b8b
commit 9be2fef0c8
2 changed files with 16 additions and 17 deletions

View File

@ -75,6 +75,6 @@ class OpenLyricsImport(SongImport):
log.exception(u'XML syntax error in file %s' % file_path) log.exception(u'XML syntax error in file %s' % file_path)
self.logError(file_path, SongStrings.XMLSyntaxError) self.logError(file_path, SongStrings.XMLSyntaxError)
except OpenLyricsError as exception: except OpenLyricsError as exception:
log.exception(u'OpenLyricsException of type %s: %s in file %s' log.exception(u'OpenLyricsException %d in file %s: %s'
% (exception.type, exception.message, file_path)) % (exception.type, file_path, exception.log_message))
self.logError(file_path, exception.display_message) self.logError(file_path, exception.display_message)

View File

@ -676,17 +676,17 @@ class OpenLyrics(object):
try: try:
lyrics = song_xml.lyrics lyrics = song_xml.lyrics
except AttributeError: except AttributeError:
raise OpenLyricsError('XML', 'Missing lyrics item', raise OpenLyricsError(OpenLyricsError.LyricsError,
'<lyrics> tag is missing.',
unicode(translate('OpenLP.OpenLyricsImportError', unicode(translate('OpenLP.OpenLyricsImportError',
'XML tree is missing <lyrics> tag. ' '<lyrics> tag is missing.')))
'It is not valid OpenLyrics file.')))
try: try:
verses = lyrics.verse verses = lyrics.verse
except AttributeError: except AttributeError:
raise OpenLyricsError('XML', 'Missing lyrics item', raise OpenLyricsError(OpenLyricsError.VerseError,
'<verse> tag is missing.',
unicode(translate('OpenLP.OpenLyricsImportError', unicode(translate('OpenLP.OpenLyricsImportError',
'XML tree is missing <verse> tag. ' '<verse> tag is missing.')))
'It is not valid OpenLyrics file.')))
# Loop over the "verse" elements. # Loop over the "verse" elements.
for verse in verses: for verse in verses:
text = u'' text = u''
@ -807,13 +807,12 @@ class OpenLyrics(object):
class OpenLyricsError(Exception): class OpenLyricsError(Exception):
""" # XML tree is missing the lyrics tag
By now raised only in case of missing lyrics or verse element in XML. LyricsError = 1
""" # XML tree has no verse tags
def __init__(self, exception_type, message, display_message): VerseError = 2
self.type = exception_type
self.message = message
self.display_message = display_message
def __str__(self): def __init__(self, type, log_message, display_message):
return "%s: %s" % (self.type, self.message) self.type = type
self.log_message = log_message
self.display_message = display_message