improve error generation and handling

This commit is contained in:
Jan Petykiewicz 2024-07-28 20:08:53 -07:00
parent 38e9d5c250
commit e159c80b0c
5 changed files with 10 additions and 10 deletions

View File

@ -409,8 +409,8 @@ def _annotations_to_properties(annotations: annotations_t, max_len: int = 126) -
for key, vals in annotations.items(): for key, vals in annotations.items():
try: try:
i = int(key) i = int(key)
except ValueError: except ValueError as err:
raise PatternError(f'Annotation key {key} is not convertable to an integer') raise PatternError(f'Annotation key {key} is not convertable to an integer') from err
if not (0 < i < 126): if not (0 < i < 126):
raise PatternError(f'Annotation key {key} converts to {i} (must be in the range [1,125])') raise PatternError(f'Annotation key {key} converts to {i} (must be in the range [1,125])')

View File

@ -298,7 +298,7 @@ def read(
cap_start = path_cap_map[element.get_extension_start()[0]] cap_start = path_cap_map[element.get_extension_start()[0]]
cap_end = path_cap_map[element.get_extension_end()[0]] cap_end = path_cap_map[element.get_extension_end()[0]]
if cap_start != cap_end: if cap_start != cap_end:
raise Exception('masque does not support multiple cap types on a single path.') # TODO handle multiple cap types raise PatternError('masque does not support multiple cap types on a single path.') # TODO handle multiple cap types
cap = cap_start cap = cap_start
path_args: dict[str, Any] = {} path_args: dict[str, Any] = {}

View File

@ -1016,10 +1016,10 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
try: try:
from matplotlib import pyplot # type: ignore from matplotlib import pyplot # type: ignore
import matplotlib.collections # type: ignore import matplotlib.collections # type: ignore
except ImportError as err: except ImportError:
logger.error('Pattern.visualize() depends on matplotlib!') logger.exception('Pattern.visualize() depends on matplotlib!\n'
logger.error('Make sure to install masque with the [visualize] option to pull in the needed dependencies.') + 'Make sure to install masque with the [visualize] option to pull in the needed dependencies.')
raise err raise
if self.has_refs() and library is None: if self.has_refs() and library is None:
raise PatternError('Must provide a library when visualizing a pattern with refs') raise PatternError('Must provide a library when visualizing a pattern with refs')

View File

@ -105,11 +105,11 @@ class Path(Shape):
custom_caps = (PathCap.SquareCustom,) custom_caps = (PathCap.SquareCustom,)
if self.cap in custom_caps: if self.cap in custom_caps:
if vals is None: if vals is None:
raise Exception('Tried to set cap extensions to None on path with custom cap type') raise PatternError('Tried to set cap extensions to None on path with custom cap type')
self._cap_extensions = numpy.array(vals, dtype=float) self._cap_extensions = numpy.array(vals, dtype=float)
else: else:
if vals is not None: if vals is not None:
raise Exception('Tried to set custom cap extensions on path with non-custom cap type') raise PatternError('Tried to set custom cap extensions on path with non-custom cap type')
self._cap_extensions = vals self._cap_extensions = vals
# vertices property # vertices property

View File

@ -221,7 +221,7 @@ def get_char_as_polygons(
'advance' distance (distance from the start of this glyph to the start of the next one) 'advance' distance (distance from the start of this glyph to the start of the next one)
""" """
if len(char) != 1: if len(char) != 1:
raise Exception('get_char_as_polygons called with non-char') raise PatternError('get_char_as_polygons called with non-char')
face = Face(font_path) face = Face(font_path)
face.set_char_size(resolution) face.set_char_size(resolution)