Skip to content

Improving error message in mapdl.get_value #1413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,11 +1577,18 @@ def _get(self, entity, entnum, item1, it1num, item2, it2num):
self._get_lock = False

if getresponse.type == 0:
raise ValueError(
"This is either an invalid get request, or MAPDL is set"
" to the wrong processor (e.g. on BEGIN LEVEL vs."
" POST26)"
self._log.debug(
"The 'grpc' get method seems to have failed. Trying old implementation for more verbose output."
)
try:
out = self.run("*GET,__temp__," + cmd)
except MapdlRuntimeError:
# Get can thrown some errors, in that case, they are caught in the default run method.
raise
else:
# Here we catch the rest of the errors and warnings
raise ValueError(out)

if getresponse.type == 1:
return getresponse.dval
elif getresponse.type == 2:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ansys.mapdl.core import examples, launch_mapdl
from ansys.mapdl.core.common_grpc import DEFAULT_CHUNKSIZE
from ansys.mapdl.core.errors import MapdlRuntimeError
from ansys.mapdl.core.launcher import check_valid_ansys, get_start_instance

PATH = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -122,7 +123,7 @@ def test_clear_multiple(mapdl):


def test_invalid_get(mapdl):
with pytest.raises(ValueError):
with pytest.raises(MapdlRuntimeError):
mapdl.get_value("ACTIVE", item1="SET", it1num="invalid")


Expand Down
8 changes: 8 additions & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,3 +1520,11 @@ def test_lsread(mapdl, cleared):
assert "No nodal" in mapdl.flist()
mapdl.lsread(mute=True)
assert "No nodal" not in mapdl.flist()


def test_get_fallback(mapdl, cleared):
with pytest.raises(ValueError, match="There are no NODES defined"):
mapdl.get_value("node", 0, "num", "maxd")

with pytest.raises(ValueError, match="There are no ELEMENTS defined"):
mapdl.get_value("elem", 0, "num", "maxd")