errors.py 845 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. class UFOLibError(Exception):
  3. pass
  4. class UnsupportedUFOFormat(UFOLibError):
  5. pass
  6. class GlifLibError(UFOLibError):
  7. """An error raised by glifLib.
  8. This class is a loose backport of PEP 678, adding a :attr:`.note`
  9. attribute that can hold additional context for errors encountered.
  10. It will be maintained until only Python 3.11-and-later are supported.
  11. """
  12. def _add_note(self, note: str) -> None:
  13. # Loose backport of PEP 678 until we only support Python 3.11+, used for
  14. # adding additional context to errors.
  15. # TODO: Replace with https://docs.python.org/3.11/library/exceptions.html#BaseException.add_note
  16. (message, *rest) = self.args
  17. self.args = ((message + "\n" + note), *rest)
  18. class UnsupportedGLIFFormat(GlifLibError):
  19. pass