From 36c64087a8757f12c7b5233a29c9df23bcc02138 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Thu, 27 Feb 2020 18:13:45 +0000 Subject: [PATCH] Add a proper message to IncludedFeaNotFound Also, minor f-string refactor. --- Lib/fontTools/feaLib/error.py | 12 ++++++++++-- Tests/feaLib/lexer_test.py | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/feaLib/error.py b/Lib/fontTools/feaLib/error.py index 82a7dec5a..66c6c6eae 100644 --- a/Lib/fontTools/feaLib/error.py +++ b/Lib/fontTools/feaLib/error.py @@ -9,10 +9,18 @@ class FeatureLibError(Exception): message = Exception.__str__(self) if self.location: path, line, column = self.location - return "%s:%d:%d: %s" % (path, line, column, message) + return f"{path}:{line}:{column}: {message}" else: return message class IncludedFeaNotFound(FeatureLibError): - pass + def __str__(self): + assert self.location is not None + + message = ( + "The following feature file should be included but cannot be found: " + f"{Exception.__str__(self)}" + ) + path, line, column = self.location + return f"{path}:{line}:{column}: {message}" diff --git a/Tests/feaLib/lexer_test.py b/Tests/feaLib/lexer_test.py index fa3f0ea57..3837801f5 100644 --- a/Tests/feaLib/lexer_test.py +++ b/Tests/feaLib/lexer_test.py @@ -178,7 +178,9 @@ class IncludingLexerTest(unittest.TestCase): def test_include_missing_file(self): lexer = IncludingLexer(self.getpath("include/includemissingfile.fea")) self.assertRaisesRegex(IncludedFeaNotFound, - "includemissingfile.fea:1:8: missingfile.fea", + "includemissingfile.fea:1:8: The following feature file " + "should be included but cannot be found: " + "missingfile.fea", lambda: list(lexer)) def test_featurefilepath_None(self):