Skip to content

Commit

Permalink
Adding more error catching (#2901)
Browse files Browse the repository at this point in the history
* Adding more error catching

* Adding more error catching

* Clearing the db first
  • Loading branch information
germa89 authored Mar 18, 2024
1 parent cda0865 commit 3c3bbae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,20 @@ def _raise_errors(self, text):
text += base_error_msg
raise ComponentNoData(text)

if "is not part of the currently active set." in flat_text:
text += base_error_msg
raise MapdlCommandIgnoredError(text)

if "No nodes defined." in flat_text:
text += base_error_msg
raise MapdlCommandIgnoredError(text)

if "For element type = " in flat_text and "is invalid." in flat_text:
if "is normal behavior when a CDB file is used." in flat_text:
warn(text)
else:
raise MapdlCommandIgnoredError(text)

# flag errors
if "*** ERROR ***" in flat_text:
self._raise_output_errors(text)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2408,3 +2408,28 @@ def test_screenshot(mapdl, make_block, tmpdir):
os.remove(file_name)

mapdl.file_type_for_plots = previous_device


def test_force_command_ignored_not_active_set(mapdl, cleared):
mapdl.prep7()
mapdl.et("", 227)
mapdl.keyopt(1, 1) # Thermal-Piezoelectric
mapdl.n(1, 0, 0, 0)

with pytest.raises(MapdlCommandIgnoredError):
mapdl.f(1, "CHRG", 10)


def test_force_command_when_no_nodes(mapdl, cleared):
mapdl.prep7()
mapdl.et(1, 189)
with pytest.raises(MapdlCommandIgnoredError, match="No nodes defined"):
mapdl.f(1, "CHRG", 0)


def test_not_correct_et_element(mapdl):
mapdl.clear()
mapdl.prep7()
mapdl.et(1, 227)
with pytest.warns(UserWarning, match="is normal behavior when a CDB file is used"):
mapdl.keyopt(1, 222)

0 comments on commit 3c3bbae

Please sign in to comment.