diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index ba18041c..3abf58cd 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -11,6 +11,7 @@ import jinja2 from patacrep import encoding, files, pkg_datapath from patacrep.songs import Song from patacrep.songs.chordpro.syntax import parse_song +from patacrep.songs.errors import FileNotFound from patacrep.templates import Renderer from patacrep.latex import lang2babel, UnknownLanguage from patacrep.files import path2posix @@ -113,20 +114,22 @@ class Chordpro2LatexSong(ChordproSong): try: return os.path.join("scores", super().search_partition(filename)) except FileNotFoundError: - LOGGER.warning( - "Song '%s' (datadir '%s'): Score '%s' not found.", - self.subpath, self.datadir, filename, + message = "Song '{}' (datadir '{}'): Score '{}' not found.".format( + self.subpath, self.datadir, filename ) + self.errors.append(FileNotFound(self, filename)) + LOGGER.warning(message) return None def search_image(self, filename): try: return os.path.join("img", super().search_image(filename)) except FileNotFoundError: - LOGGER.warning( - "Song '%s' (datadir '%s'): Image '%s' not found.", - self.subpath, self.datadir, filename, + message = "Song '{}' (datadir '{}'): Image '{}' not found.".format( + self.subpath, self.datadir, filename ) + self.errors.append(FileNotFound(self, filename)) + LOGGER.warning(message) return None def _jinja2_filters(self): diff --git a/patacrep/songs/errors.py b/patacrep/songs/errors.py index 289aa099..7c9bac4b 100644 --- a/patacrep/songs/errors.py +++ b/patacrep/songs/errors.py @@ -29,5 +29,8 @@ class SongSyntaxError(SongError): else: return "Song {}: {}".format(self.song, self.message) -# class FileError(SongError): -# type = "file" +class FileNotFound(SongError): + """File not found error""" + + def __init__(self, song, filename): + super().__init__(song, "File '{}' not found.".format(filename))