DiamondLightSource / DiamondLightSource/fastcs

Failing to set path of root controller leads to unhelpful error message

Open Beginner friendly
#416 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
6
Forks
8
Avg merge
2d 12h
Merged PRs (30d)
3

Description

If you create a controller but do not call `controller.set_path()` on it, the error message created is somewhat unhelpful:

## Steps To Reproduce
```
from fastcs.attributes import AttrR
from fastcs.controllers import Controller
from fastcs.datatypes import Int
from fastcs.launch import FastCS
from fastcs.transports.epics.ca.transport import EpicsCATransport

class TemperatureController(Controller):
devid = AttrR(Int())

epics_ca = EpicsCATransport()
controller = TemperatureController()
# controller.set_path(["DEMO"]) # Uncomment this line and it will execute
fastcs = FastCS(controller, [epics_ca])

if __name__ == "__main__":
fastcs.run()
```

The error printed is:
```
Traceback (most recent call last):
File "/workspaces/fastcs-bacnet/mytest.py", line 18, in
fastcs.run()
File "/cache/venv-for/scratch/eyh46967/dev/bacnet/fastcs-bacnet/lib/python3.12/site-packages/fastcs/control_system.py", line 85, in run
self._loop.run_until_complete(serve)
File "/root/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/cache/venv-for/scratch/eyh46967/dev/bacnet/fastcs-bacnet/lib/python3.12/site-packages/fastcs/control_system.py", line 147, in serve
transport.connect(controller_apis=self.controller_apis, loop=self._loop)
File "/cache/venv-for/scratch/eyh46967/dev/bacnet/fastcs-bacnet/lib/python3.12/site-packages/fastcs/transports/epics/ca/transport.py", line 42, in connect
validate_ca_id(api)
File "/cache/venv-for/scratch/eyh46967/dev/bacnet/fastcs-bacnet/lib/python3.12/site-packages/fastcs/transports/epics/ca/util.py", line 26, in validate_ca_id
validate_epics_pv_id(controller_api, transport_label="EPICS CA id", id_re=_CA_ID_RE)
File "/cache/venv-for/scratch/eyh46967/dev/bacnet/fastcs-bacnet/lib/python3.12/site-packages/fastcs/transports/epics/util.py", line 35, in validate_epics_pv_id
name = controller_api.path[0]
~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
```

## Acceptance Criteria
- A more informative error message is displayed

Please note I've only tested this with the "EpicsCATransport", I don't know what exactly happens with other Transports.

Contributor guide

Open the contributing guide

Research direction

Start with fastcs/transports/epics/util.py and fastcs/transports/epics/ca/util.py, following the validation path shown in the traceback. Reproduce the controller without set_path() using the issue's example, then verify that the failure explains the missing path instead of exposing an IndexError. Consider whether the same behavior is relevant to other transports, as the report does not confirm them.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.