From 235e8c6fcfb8e6fa7e8d4c4eb334e6d5b633dd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Thu, 15 Dec 2011 13:53:51 +0200 Subject: [PATCH] Use generated exceptions instead to make more specific errors. --- openlp/plugins/songs/lib/openlyricsimport.py | 5 ++++- openlp/plugins/songs/lib/xml.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/openlyricsimport.py b/openlp/plugins/songs/lib/openlyricsimport.py index 42d075c51..784a16b72 100644 --- a/openlp/plugins/songs/lib/openlyricsimport.py +++ b/openlp/plugins/songs/lib/openlyricsimport.py @@ -70,6 +70,9 @@ class OpenLyricsImport(SongImport): parsed_file = etree.parse(open(file_path, u'r'), parser) xml = unicode(etree.tostring(parsed_file)) self.openLyrics.xml_to_song(xml) - except etree.XMLSyntaxError, AttributeError: + except etree.XMLSyntaxError: log.exception(u'XML syntax error in file %s' % file_path) self.logError(file_path, SongStrings.XMLSyntaxError) + except Exception as values: + log.exception(u'%s in file %s' % (values[0], file_path)) + self.logError(file_path, SongStrings.XMLSyntaxError) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index b16db7e94..578e66c98 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -673,9 +673,16 @@ class OpenLyrics(object): sxml = SongXML() verses = {} verse_def_list = [] - lyrics = song_xml.lyrics + try: + lyrics = song_xml.lyrics + except AttributeError: + raise Exception('XML error, missing lyrics item') + try: + verses = lyrics.verse + except AttributeError: + raise Exception('XML error, missing verse item') # Loop over the "verse" elements. - for verse in lyrics.verse: + for verse in verses: text = u'' # Loop over the "lines" elements. for lines in verse.lines: