diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 40dd9dccf..c3210b2a6 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -7530,6 +7530,7 @@ def fillet( :param history: If given, the operation is recorded in this history. :param name: Name under which the operation is recorded in ``history``. :return: The filleted shape. + :raises ValueError: If the fillet cannot be built. """ builder = BRepFilletAPI_MakeFillet(_get_one(s, (Shell, Solid)).wrapped,) @@ -7539,6 +7540,9 @@ def fillet( builder.Build() + if not builder.IsDone(): + raise ValueError("Fillet failed, try a smaller radius or fewer edges") + _update_history(history, name, [s, edges], builder) return _compound_or_shape(builder.Shape()) @@ -7560,6 +7564,7 @@ def chamfer( :param history: If given, the operation is recorded in this history. :param name: Name under which the operation is recorded in ``history``. :return: The chamfered shape. + :raises ValueError: If the chamfer cannot be built. """ builder = BRepFilletAPI_MakeChamfer(_get_one(s, (Shell, Solid)).wrapped,) @@ -7569,6 +7574,9 @@ def chamfer( builder.Build() + if not builder.IsDone(): + raise ValueError("Chamfer failed, try a smaller distance or fewer edges") + _update_history(history, name, [s, edges], builder) return _compound_or_shape(builder.Shape()) diff --git a/tests/test_free_functions.py b/tests/test_free_functions.py index 3802aefd8..52437f321 100644 --- a/tests/test_free_functions.py +++ b/tests/test_free_functions.py @@ -1023,6 +1023,14 @@ def test_chamfer(): assert r.faces(">Z").Area() < 1 +@pytest.mark.parametrize("op", [fillet, chamfer]) +def test_fillet_chamfer_raises(box_shape, op): + + # too large to fit, the op must raise instead of crashing + with raises(ValueError): + op(box_shape, box_shape.edges(), 0.5) + + @pytest.mark.parametrize("sel, n", [("|Z", 4), (">X and >Y", 1)]) def test_fillet_chamfer_methods_shape_arg(sel, n):