Skip to content

Commit

Permalink
feaLib: add IncludedFeaNotFound error
Browse files Browse the repository at this point in the history
subclass of FeatureLibError, only raised if IOError.errno == ENOENT (i.e. FileNotFoundError)

googlefonts/fontmake#157 (comment)

Will be useful in ufo2ft to detect when an included feature file doesn't exist and print a nicer error message
explaining that includes must be relative to the UFO itself, and not relative to the embedded features.fea file.

unified-font-object/ufo-spec#55
  • Loading branch information
anthrotype committed Feb 21, 2018
1 parent 767b931 commit 7d7212b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Lib/fontTools/feaLib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ def __str__(self):
return "%s:%d:%d: %s" % (path, line, column, message)
else:
return message


class IncludedFeaNotFound(FeatureLibError):
pass
8 changes: 6 additions & 2 deletions Lib/fontTools/feaLib/lexer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function, division, absolute_import
from __future__ import unicode_literals
from fontTools.misc.py23 import *
from fontTools.feaLib.error import FeatureLibError
from fontTools.feaLib.error import FeatureLibError, IncludedFeaNotFound
import re
import os

Expand Down Expand Up @@ -231,7 +231,11 @@ def make_lexer_(file_or_path, location=None):
try:
fileobj = open(filename, "r", encoding="utf-8")
except IOError as err:
raise FeatureLibError(str(err), location)
# FileNotFoundError does not exist on Python < 3.3
import errno
if err.errno == errno.ENOENT:
raise IncludedFeaNotFound(str(err), location)
raise # pragma: no cover
data = fileobj.read()
filename = fileobj.name if hasattr(fileobj, "name") else "<features>"
if closing:
Expand Down

0 comments on commit 7d7212b

Please sign in to comment.