Merge pull request #188 from daltonmaag/errors-refactor

Order exceptions hierarchically
This commit is contained in:
Nikolaus Waxweiler 2020-02-07 12:34:39 +00:00 committed by GitHub
commit 3cbd848322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 24 deletions

View File

@ -26,6 +26,7 @@ except ImportError:
import math
from .errors import Error as Cu2QuError, ApproxNotFoundError
__all__ = ['curve_to_quadratic', 'curves_to_quadratic']
@ -42,16 +43,6 @@ else:
COMPILED = False
class Cu2QuError(Exception):
pass
class ApproxNotFoundError(Cu2QuError):
def __init__(self, curve):
message = "no approximation found: %s" % curve
super(Cu2QuError, self).__init__(message)
self.curve = curve
@cython.cfunc
@cython.inline
@cython.returns(cython.double)

View File

@ -13,6 +13,8 @@ try:
except ImportError:
basestring = str
from .errors import InvalidTypeSpecification
# BEGIN shameless copy from Cython/minivect/minitypes.py
@ -46,8 +48,6 @@ def index_type(base_type, item):
a 2D strided array of doubles. The syntax is the same as for
Cython memoryviews.
"""
class InvalidTypeSpecification(Exception):
pass
def verify_slice(s):
if s.start or s.stop or s.step not in (None, 1):

View File

@ -1,12 +1,22 @@
from __future__ import print_function, absolute_import, division
class UnequalZipLengthsError(ValueError):
class Error(Exception):
"""Base Cu2Qu exception class for all other errors."""
class ApproxNotFoundError(Error):
def __init__(self, curve):
message = "no approximation found: %s" % curve
super(Error, self).__init__(message)
self.curve = curve
class UnequalZipLengthsError(Error):
pass
class IncompatibleGlyphsError(ValueError):
class IncompatibleGlyphsError(Error):
def __init__(self, glyphs):
assert len(glyphs) > 1
self.glyphs = glyphs
@ -21,14 +31,13 @@ class IncompatibleGlyphsError(ValueError):
class IncompatibleSegmentNumberError(IncompatibleGlyphsError):
def __str__(self):
return "Glyphs named %s have different number of segments" % (
self.combined_name)
self.combined_name
)
class IncompatibleSegmentTypesError(IncompatibleGlyphsError):
def __init__(self, glyphs, segments):
IncompatibleGlyphsError.__init__(self, glyphs)
self.segments = segments
@ -37,17 +46,24 @@ class IncompatibleSegmentTypesError(IncompatibleGlyphsError):
lines = []
ndigits = len(str(max(self.segments)))
for i, tags in sorted(self.segments.items()):
lines.append("%s: (%s)" % (
str(i).rjust(ndigits), ", ".join(repr(t) for t in tags)))
lines.append(
"%s: (%s)" % (str(i).rjust(ndigits), ", ".join(repr(t) for t in tags))
)
return "Glyphs named %s have incompatible segment types:\n %s" % (
self.combined_name, "\n ".join(lines))
self.combined_name,
"\n ".join(lines),
)
class IncompatibleFontsError(ValueError):
class IncompatibleFontsError(Error):
def __init__(self, glyph_errors):
self.glyph_errors = glyph_errors
def __str__(self):
return "fonts contains incompatible glyphs: %s" % (
", ".join(repr(g) for g in sorted(self.glyph_errors.keys())))
", ".join(repr(g) for g in sorted(self.glyph_errors.keys()))
)
class InvalidTypeSpecification(Error):
pass