Merge pull request #1186 from anthrotype/included-not-found

feaLib: add IncludedFeaNotFound error
This commit is contained in:
Cosimo Lupo 2018-02-21 17:12:27 +00:00 committed by GitHub
commit ea5980b6ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -14,3 +14,7 @@ class FeatureLibError(Exception):
return "%s:%d:%d: %s" % (path, line, column, message)
else:
return message
class IncludedFeaNotFound(FeatureLibError):
pass

View File

@ -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
@ -231,7 +231,11 @@ class IncludingLexer(object):
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: