Skip to content

Commit

Permalink
Session to raise ToolkitError instead of RuntimeError
Browse files Browse the repository at this point in the history
  • Loading branch information
markheik committed Apr 17, 2023
1 parent 5970f7d commit ae22504
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/zhinst/toolkit/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,13 +881,18 @@ def raw_path_to_node(
Corresponding toolkit node object.
Raises:
RuntimeError: If the node does not belong to the optional module or
ValueError: If the `raw_path` does not start with a leading dash.
ToolkitError: If the node does not belong to the optional module or
to a connected device.
.. versionchanged:: 0.5.3
Changed `RuntimeError` to `ValueError`.
"""
if not raw_path.startswith("/"):
raise RuntimeError(
raise ValueError(
f"{raw_path} does not seem to be an absolute path. "
"(it must start with a leading slash)"
"It must start with a leading slash."
)
if module is not None:
node = module.root.raw_path_to_node(raw_path)
Expand All @@ -899,7 +904,7 @@ def raw_path_to_node(
return self.root.raw_path_to_node(raw_path)
return self.devices[serial].root.raw_path_to_node(raw_path)
except KeyError as error:
raise RuntimeError(
raise ToolkitError(
f"Node belongs to a device({raw_path.split('/')[1]}) not connected to "
"the Data Server."
) from error
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data_server_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def get_string_side_effect(arg):
assert result.root.prefix_hide == "dev1234"

# Only absolut paths are supported
with pytest.raises(RuntimeError) as e_info:
with pytest.raises(ValueError) as e_info:
session.raw_path_to_node("dev1234/test/a/b/c")

# Not connected device
Expand Down

0 comments on commit ae22504

Please sign in to comment.