Commit 1089f2da authored by Linus Pithan's avatar Linus Pithan
Browse files

umv, umvr: add custom error messages targeting the commandline user

parent 82d2854f
...@@ -881,9 +881,9 @@ def typecheck_var_args_pattern(args_pattern, empty_var_pos_args_allowed=False): ...@@ -881,9 +881,9 @@ def typecheck_var_args_pattern(args_pattern, empty_var_pos_args_allowed=False):
if param.kind == inspect.Parameter.VAR_POSITIONAL: if param.kind == inspect.Parameter.VAR_POSITIONAL:
var_args = args[i:] var_args = args[i:]
if not empty_var_pos_args_allowed and len(var_args) == 0: if not empty_var_pos_args_allowed and len(var_args) == 0:
raise RuntimeError(f"Arguments of type {args_pattern} missing!") raise TypeError(f"Arguments of type {args_pattern} missing!")
if len(var_args) % len(args_pattern) != 0: if len(var_args) % len(args_pattern) != 0:
raise RuntimeError( raise TypeError(
f"Wrong number of arguments (not a multiple of {len(args_pattern)} [{args_pattern}])" f"Wrong number of arguments (not a multiple of {len(args_pattern)} [{args_pattern}])"
) )
for j, a in enumerate(var_args): for j, a in enumerate(var_args):
......
...@@ -42,7 +42,12 @@ from bliss.common.protocols import CounterContainer ...@@ -42,7 +42,12 @@ from bliss.common.protocols import CounterContainer
from bliss.common import measurementgroup from bliss.common import measurementgroup
from bliss.common.soft_axis import SoftAxis from bliss.common.soft_axis import SoftAxis
from bliss.common.counter import SoftCounter, Counter from bliss.common.counter import SoftCounter, Counter
from bliss.common.utils import ShellStr, typecheck_var_args_pattern, modify_annotations from bliss.common.utils import (
ShellStr,
typecheck_var_args_pattern,
modify_annotations,
custom_error_msg,
)
from bliss.common.measurementgroup import MeasurementGroup from bliss.common.measurementgroup import MeasurementGroup
# objects given to Bliss shell user # objects given to Bliss shell user
...@@ -509,6 +514,12 @@ def wm(*axes: _scannable_or_name, **kwargs): ...@@ -509,6 +514,12 @@ def wm(*axes: _scannable_or_name, **kwargs):
print(_tabulate(table).replace("~", " ")) print(_tabulate(table).replace("~", " "))
@custom_error_msg(
TypeError,
"intended usage: umv(motor1, target_position_1, motor2, target_position_2, ... )",
new_exeption_type=RuntimeError,
display_original_msg=False,
)
@modify_annotations({"args": "motor1, pos1, motor2, pos2, ..."}) @modify_annotations({"args": "motor1, pos1, motor2, pos2, ..."})
@typecheck_var_args_pattern([_scannable, _float]) @typecheck_var_args_pattern([_scannable, _float])
def umv(*args): def umv(*args):
...@@ -521,6 +532,12 @@ def umv(*args): ...@@ -521,6 +532,12 @@ def umv(*args):
__umove(*args) __umove(*args)
@custom_error_msg(
TypeError,
"intended usage: umv(motor1, relative_displacement_1, motor2, relative_displacement_2, ... )",
new_exeption_type=RuntimeError,
display_original_msg=False,
)
@modify_annotations({"args": "motor1, rel. pos1, motor2, rel. pos2, ..."}) @modify_annotations({"args": "motor1, rel. pos1, motor2, rel. pos2, ..."})
@typecheck_var_args_pattern([_scannable, _float]) @typecheck_var_args_pattern([_scannable, _float])
def umvr(*args): def umvr(*args):
......
...@@ -201,7 +201,7 @@ def test_umv_typecheck(session): ...@@ -201,7 +201,7 @@ def test_umv_typecheck(session):
umv(m0, 1.2) umv(m0, 1.2)
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
umv(m0, 1, 2) umv(m0, 1, 2)
with pytest.raises(TypeError): with pytest.raises(RuntimeError):
umv(1, m0) umv(1, m0)
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
umv() umv()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment