Skip to content

Commit e1d656c

Browse files
committed
Handle the unspecified dispatch event type explicitly
mypy's `exhaustive-match` check (enabled by the `frequenz-repo-config` 0.19.0 migration) reports that the `match` over the event type in the dispatch stream is missing a case for `Event.UNSPECIFIED`, the enum's zero value. The dispatch API should never actually send this, but the enum allows for it, and the `match` previously covered it only by falling through silently. Add an explicit case, so a malformed event logs a warning and gets skipped instead of crashing the whole background service, and the lack of behaviour beyond that is a documented decision rather than an oversight. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 6598028 commit e1d656c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/frequenz/dispatch/_bg_service.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ async def _run(self) -> None: # pylint: disable=too-many-branches
341341
await self._lifecycle_events_tx.send(
342342
Deleted(dispatch=new_dispatch)
343343
)
344+
case Event.UNSPECIFIED:
345+
# The API should never send this in
346+
# practice, but the enum allows for it,
347+
# so log and ignore it rather than crash
348+
# the whole service on garbage input.
349+
_logger.warning(
350+
"Received dispatch event with an "
351+
"unspecified event type: %s",
352+
selected.message,
353+
)
344354

345355
case StreamRetrying():
346356
is_retry_attempt = True

0 commit comments

Comments
 (0)