typemytype / booleanOperations

Boolean operations on paths
MIT License
38 stars 18 forks source link

raise custom exceptions when pyclipper fails #37

Closed anthrotype closed 7 years ago

anthrotype commented 7 years ago

When an invalid contour is received as a subject or clipping path, pyclipper raises its own ClipperException error.

I wouldn't want clients to have to import pyclipper in order to handle the exception. I believe that should stay private as we may decide to replace pyclipper with another implementation in the future.

So we need to define our own custom exceptions, and re-raise the pyclipper.ClipperException as booleanOperations.BooleanOperationsError.

For example, one could do:

import booleanOperations

try:
    # perform some booleanOpertions
except booleanOperations.BooleanOperationsError:
    # handle the exception

The custom errors are defined in the booleanOperations.exceptions module. For convenience, the generic one is also exported in the top-level module as booleanOperations.BooleanOperationsError.

Note that previously, we were calling pyclipper's AddPaths method, which only raised when all the input path are invalid; I replaced it with AddPath (in a loop), so we can raise when any input path is invalid, and report which one in the exception message, so the user can find it more easily.

anthrotype commented 7 years ago

@typemytype shall I tag and publish v0.6.0 with the new custom exceptions?

typemytype commented 7 years ago

Yes please Thanks

On Monday, 17 October 2016, Cosimo Lupo notifications@github.com wrote:

@typemytype https://github.com/typemytype shall I tag and publish v0.6.0 with the new custom exceptions?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/typemytype/booleanOperations/pull/37#issuecomment-254315429, or mute the thread https://github.com/notifications/unsubscribe-auth/ABIp1ll7CsXvX68RYkj59ZYjpAJ5boN4ks5q09MVgaJpZM4KYifW .

gr Frederik www.typemytype.com