Skip to content

Blueapi context should except when it can't find an injected device  #633

Closed

Description

@noemifrisina

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

  1. callumforrester commented on Sep 12, 2024

    @callumforrester
    Contributor

    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?

  2. noemifrisina commented on Sep 12, 2024

    @noemifrisina
    ContributorAuthor

    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?

  3. callumforrester commented on Sep 13, 2024

    @callumforrester
    Contributor

    Depends, the information we want is known at startup so you could conceivably have a message saying

    The following devices were not found:
    - d1
    - d2
    - d3
    - d4
    - ... (all of them)
    This means the following plans will be unavailable:
    - p1
    - p2
    - p3
    - ... (some of them)

    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?

  4. noemifrisina commented on Sep 13, 2024

    @noemifrisina
    ContributorAuthor

    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.

  5. added
    enhancement
    c: worker
    on Oct 8, 2024
  6. tpoliaw commented on Jun 23, 2025

    @tpoliaw
    Contributor

    Plans now return an error when they're submitted if the device can't be found (or is not the correct type).

    $ blueapi controller run --bg count '{"detectors": ["foo"]}'
    Error: Incorrect parameters supplied
        Invalid value 'foo' for field detectors.0: Value error, Device foo is not of type bluesky.protocols.Readable
    

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: workerenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions