This commit annotates errors from GlyphSet.readGlyph() with the details of the glyph that originated them (e.g. name, path to glif). This is implemented with a loose backport of PEP678, to avoid adding a wrapper error that would be less specific and would break API compatibility. In addition, this commit adds a test to ensure that the new details are present (specifically, in the case of parsing invalid XML).
23 lines
584 B
Python
23 lines
584 B
Python
from __future__ import annotations
|
|
|
|
|
|
class UFOLibError(Exception):
|
|
pass
|
|
|
|
|
|
class UnsupportedUFOFormat(UFOLibError):
|
|
pass
|
|
|
|
|
|
class GlifLibError(UFOLibError):
|
|
def _add_note(self, note: str) -> None:
|
|
# Loose backport of PEP 678 until we only support Python 3.11+, used for
|
|
# adding additional context to errors.
|
|
# TODO: Replace with https://docs.python.org/3.11/library/exceptions.html#BaseException.add_note
|
|
(message, *rest) = self.args
|
|
self.args = ((message + "\n" + note), *rest)
|
|
|
|
|
|
class UnsupportedGLIFFormat(GlifLibError):
|
|
pass
|