Skip to content
Merged
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
27 changes: 22 additions & 5 deletions src/fastcs/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ async def update(self, value: T) -> None:
self._value = self._datatype.validate(value)

if self._on_update_callbacks is not None:
await asyncio.gather(*[cb(self._value) for cb in self._on_update_callbacks])
try:
await asyncio.gather(
*[cb(self._value) for cb in self._on_update_callbacks]
)
except Exception as e:
logger.opt(exception=e).error(
"On update callback failed", attribute=self, value=value
)

def add_on_update_callback(self, callback: AttrOnUpdateCallback[T]) -> None:
"""Add a callback to be called when the value of the attribute is updated
Expand Down Expand Up @@ -197,8 +204,8 @@ async def update_attribute():
try:
self.log_event("Update attribute", topic=self)
await update_callback(self)
except Exception:
logger.opt(exception=True).error("Update loop failed", attribute=self)
except Exception as e:
logger.opt(exception=e).error("Update loop failed", attribute=self)
raise

return update_attribute
Expand Down Expand Up @@ -246,10 +253,20 @@ async def put(self, setpoint: T, sync_setpoint: bool = False) -> None:
"""
setpoint = self._datatype.validate(setpoint)
if self._on_put_callback is not None:
await self._on_put_callback(self, setpoint)
try:
await self._on_put_callback(self, setpoint)
except Exception as e:
logger.opt(exception=e).error(
"Put failed", attribute=self, setpoint=setpoint
)

if sync_setpoint:
await self._call_sync_setpoint_callbacks(setpoint)
try:
await self._call_sync_setpoint_callbacks(setpoint)
except Exception as e:
logger.opt(exception=e).error(
"Sync setpoint failed", attribute=self, setpoint=setpoint
)

async def _call_sync_setpoint_callbacks(self, setpoint: T) -> None:
if self._sync_setpoint_callbacks:
Expand Down
4 changes: 2 additions & 2 deletions src/fastcs/control_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ async def block_forever():
await asyncio.gather(*coros)
except asyncio.CancelledError:
pass
except Exception as e:
raise RuntimeError("Unhandled exception in serve") from e
except Exception:
logger.exception("Unhandled exception in serve")
finally:
logger.info("Shutting down FastCS")
self._stop_scan_tasks()
Expand Down
21 changes: 12 additions & 9 deletions src/fastcs/transport/epics/pva/pvi_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ def make_p4p_value(self) -> Value:
raw_value = self._make_p4p_raw_value()
p4p_type = self._make_type_for_raw_value(raw_value)

return Value(
p4p_type,
{
**p4p_alarm_states(),
**p4p_timestamp_now(),
**display,
"value": raw_value,
},
)
try:
return Value(
p4p_type,
{
**p4p_alarm_states(),
**p4p_timestamp_now(),
**display,
"value": raw_value,
},
)
except KeyError as e:
raise ValueError(f"Failed to create p4p Value from {raw_value}") from e

def make_provider(
self,
Expand Down