Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,13 @@ def __get_pydantic_core_schema__(
) -> CoreSchema:
def valid(value):
val = self.find_device(value)
if not val or not is_compatible(
val, cls.origin or target, cls.args
):
if not val:
device_names = list(self.devices.keys())
raise ValueError(
f"Device {value} cannot be found, "
f"available devices are: {device_names}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since devices are a tree and blueapi supports resolving them recursively (foo.bar.baz etc.), devices.keys() is not the complete set of available devices. So you might just get [sample_stage] instead of [sample_stage.x, sample_stage.y], for example. Not sure if it really matters here but worth knowing.

Relates to #1129

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, @tpoliaw beat me to it

)
elif not is_compatible(val, cls.origin or target, cls.args):
required = qualified_generic_name(target)
raise ValueError(
f"Device {value} is not of type {required}"
Expand Down
5 changes: 3 additions & 2 deletions tests/unit_tests/worker/test_task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,13 @@ def injected_device_plan(
assert params["dev"] == fake_device


def test_missing_injected_devices_fail_early(
def test_missing_injected_devices_fail_early_and_give_list_of_known_devices(
context: BlueskyContext,
):
def missing_injection(dev: FakeDevice = inject("does_not_exist")) -> MsgGenerator:
yield from ()

context.register_plan(missing_injection)
with pytest.raises(ValueError):
with pytest.raises(ValueError) as excinfo:
Task(name="missing_injection").prepare_params(context)
assert "fake_device" in str(excinfo.value)