Better OTL builder errors (#3286)

* Raise a sensible error for keyerror

* Try harder to find error locations

* Chain exception
This commit is contained in:
Simon Cozens 2023-10-05 11:09:22 +01:00 committed by GitHub
parent 05dc231072
commit c5295d2f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -844,10 +844,15 @@ class Builder(object):
feature=None,
)
lookups.append(lookup)
try:
otLookups = [l.build() for l in lookups]
except OpenTypeLibError as e:
raise FeatureLibError(str(e), e.location) from e
otLookups = []
for l in lookups:
try:
otLookups.append(l.build())
except OpenTypeLibError as e:
raise FeatureLibError(str(e), e.location) from e
except Exception as e:
location = self.lookup_locations[tag][str(l.lookup_index)].location
raise FeatureLibError(str(e), location) from e
return otLookups
def makeTable(self, tag):

View File

@ -55,7 +55,11 @@ def buildCoverage(glyphs, glyphMap):
if not glyphs:
return None
self = ot.Coverage()
self.glyphs = sorted(set(glyphs), key=glyphMap.__getitem__)
try:
self.glyphs = sorted(set(glyphs), key=glyphMap.__getitem__)
except KeyError as e:
raise ValueError(f"Could not find glyph {e} in font") from e
return self