Merge pull request #2595 from fonttools/hb-repack-logging

[otBase] demote repacker ERROR to WARNING, only 1 per loop; don't exit at first failure
This commit is contained in:
Cosimo Lupo 2022-04-22 19:20:03 +01:00 committed by GitHub
commit 071915cda5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 17 deletions

View File

@ -96,6 +96,7 @@ class BaseTTXConverter(DefaultTable):
self.tableTag,
)
hb_first_error_logged = False
while True:
try:
writer = OTTableWriter(tableTag=self.tableTag)
@ -109,19 +110,22 @@ class BaseTTXConverter(DefaultTable):
log.debug("serializing '%s' with hb.repack", self.tableTag)
return writer.getAllDataUsingHarfbuzz()
except (ValueError, MemoryError, hb.RepackerError) as e:
if use_hb_repack is None:
# Only log hb repacker errors the first time they occur in
# the offset-overflow resolution loop, they are just noisy.
# Maybe we can revisit this if/when uharfbuzz actually gives
# us more info as to why hb.repack failed...
if not hb_first_error_logged:
error_msg = f"{type(e).__name__}"
if str(e) != "":
error_msg += f": {e}"
log.error(
log.warning(
"hb.repack failed to serialize '%s', reverting to "
"pure-python serializer; the error message was: %s",
self.tableTag,
error_msg,
)
return writer.getAllData(remove_duplicate=False)
# let the error propagate if USE_HARFBUZZ_REPACKER is True
raise
hb_first_error_logged = True
return writer.getAllData(remove_duplicate=False)
return writer.getAllData()
except OTLOffsetOverflowError as e:

View File

@ -847,18 +847,11 @@ class SubsetTest:
args.append("--no-harfbuzz-repacker")
# elif enabled is None: ... is the default
if enabled is True:
if not installed:
# raise if enabled but not installed
with pytest.raises(ImportError, match="uharfbuzz"):
subset.main(args)
return
elif not ok:
# raise if enabled but fails
with pytest.raises(hb.RepackerError, match="mocking"):
subset.main(args)
return
if enabled is True and not installed:
# raise if enabled but not installed
with pytest.raises(ImportError, match="uharfbuzz"):
subset.main(args)
return
with caplog.at_level(logging.DEBUG, "fontTools.ttLib.tables.otBase"):
subset.main(args)