Skip to content

Commit 4f498c1

Browse files
authored
add ability to ignore errors (#342)
1 parent 4aa3e00 commit 4f498c1

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

ansys/mapdl/core/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Version of ansys-mapdl-core module."""
22

33
# major, minor, patch
4-
version_info = 0, 57, 4
4+
version_info = 0, 57, 5
55

66
# Nice string for the version
77
__version__ = '.'.join(map(str, version_info))

ansys/mapdl/core/mapdl.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def __init__(self, loglevel='DEBUG', use_vtk=True, log_apdl=False, local=True,
124124
self._vget_arr_counter = 0
125125
self._start_parm = start_parm
126126
self._path = start_parm.get('run_location', None)
127+
self._ignore_errors = False
127128

128129
self._log = setup_logger(loglevel.upper())
129130
self._log.debug('Logging set to %s', loglevel)
@@ -1765,9 +1766,15 @@ def run(self, command, write_to_log=True, **kwargs):
17651766
text += '\n\nIgnore these messages by setting allow_ignore=True'
17661767
raise MapdlInvalidRoutineError(text)
17671768

1768-
if '*** ERROR ***' in self._response: # flag error
1769-
self._log.error(self._response)
1770-
raise MapdlRuntimeError(self._response)
1769+
# flag error
1770+
if '*** ERROR ***' in self._response and not self._ignore_errors:
1771+
# remove "is turning inside out" as this allows the
1772+
# solution to continue
1773+
sub = re.sub(r'(\*\*\* ERROR \*\*\*).*[\r\n]+.*is turning inside out.',
1774+
'', self._response)
1775+
if '*** ERROR ***' in sub:
1776+
self._log.error(self._response)
1777+
raise MapdlRuntimeError(self._response)
17711778

17721779
# special returns for certain geometry commands
17731780
short_cmd = parse_to_short_cmd(command)
@@ -1782,6 +1789,20 @@ def run(self, command, write_to_log=True, **kwargs):
17821789

17831790
return self._response
17841791

1792+
@property
1793+
def ignore_errors(self):
1794+
"""Flag to ignore MAPDL errors.
1795+
1796+
Normally, any string containing "*** ERROR ***" from MAPDL
1797+
will trigger a ``MapdlRuntimeError``. Set this to ``True`` to
1798+
ignore these errors.
1799+
"""
1800+
return self._ignore_errors
1801+
1802+
@ignore_errors.setter
1803+
def ignore_errors(self, value):
1804+
self._ignore_errors = bool(value)
1805+
17851806
# @supress_logging
17861807
def load_table(self, name, array, var1='', var2='', var3=''):
17871808
"""Load a table from Python to MAPDL

tests/test_mapdl.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,24 @@ def test_al(cleared, mapdl):
194194
assert a0 == 1
195195

196196

197-
def test_invalid_area(mapdl):
197+
def test_error(mapdl):
198198
with pytest.raises(MapdlRuntimeError):
199199
mapdl.a(0, 0, 0, 0)
200200

201201

202+
def test_ignore_error(mapdl):
203+
assert not mapdl.ignore_errors
204+
mapdl.ignore_errors = True
205+
assert mapdl.ignore_errors is True
206+
207+
# verify that an error is not raised
208+
out = mapdl._run('A, 0, 0, 0')
209+
assert '*** ERROR ***' in out
210+
211+
mapdl.ignore_error = False
212+
assert mapdl.ignore_error is False
213+
214+
202215
def test_invalid_input(mapdl):
203216
with pytest.raises(FileNotFoundError):
204217
mapdl.input('thisisnotafile')

0 commit comments

Comments
 (0)