Closed
Labels
Description
As a user, I would like for the blueapi context to raise an exception when it's unable to find a device injected into a plan using Dodal's inject function.
I ran into this issue while running a plan from the command line on I24 with blueapi -c config.yaml controller run moveto .... The plan did not work and there was no indication of what was wrong except for an error in the dodal logs indicating that instead of the PMAC device only a string was passed as argument.
Here's the plan
def moveto(place: str = "origin", pmac: PMAC = inject("pmac")) -> MsgGenerator:
...i
if place == "zero":
yield from bps.trigger(pmac.to_xyz_zero)
...and the error trace from the dodal logs
[I 240910 15:06:48.746 i24ssx_Chip_Manager_py3v1:613] Chip aspecific move.
[E 240910 15:06:48.747 run_engine:1733] Run aborted
Traceback (most recent call last):
File "/dls_sw/i24/software/bluesky/mx_bluesky_testing/mx-bluesky/.venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1588, in _run
msg = self._plan_stack[-1].send(resp)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/dls_sw/i24/software/bluesky/mx_bluesky_testing/mx-bluesky/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py", line 614, in moveto
yield from bps.trigger(pmac.to_xyz_zero)
^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'to_xyz_zero'
The docs seem to suggest that the context excepts when there's no device (here), but this does not seem to be the case...
Activity
callumforrester commentedon Sep 12, 2024
This relates to a bug: #503; the error message used to be better.
@noemifrisina do you have a preference between raising on startup (and thus never making the plan available in the first place) or raising when a user tries to run the plan?
noemifrisina commentedon Sep 12, 2024
I don't really have a strong preference. I think raising when trying to run a plan may be enough to have an indication of what's wrong, as long as it fails right away and not after going through some bits of the plan...
Also, in this case I'm starting to suspect it was a problem with all the devices and raising on start-up might not have been helpful?
callumforrester commentedon Sep 13, 2024
Depends, the information we want is known at startup so you could conceivably have a message saying
It seems silly not to tell the user that those plans will not work until they try if we already know they won't. But then all that information could get lost in the noise so maybe the answer is both?
noemifrisina commentedon Sep 13, 2024
Yes, that's a good point. I still think we should raise an exception that makes it clear the problem was the device not being found if one attempts to run the plan. In a case such as the one on I24 I can see the list of devices not found being long enough that one would notice on start up and not even try but as you mentioned one or two devices might get lost in the noise.
tpoliaw commentedon Jun 23, 2025
Plans now return an error when they're submitted if the device can't be found (or is not the correct type).
It should perhaps differentiate between a device being missing and a device being the wrong type but for now the plan does fail with a mostly useful error message.