Skip to content

Commit 2bcebfd

Browse files
committed
Remove SelectErrorGroup
This exception is very niche, is not really intended to be caught by the users, as it should only happen when there is something really wrong. If there is any unexpected error during finalization, we just raise a `BaseExceptionGroup`, which will be automatically converted to a regular `ExceptionGroup` by Python if there are no `BaseException`s in the group. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent cb0ed1e commit 2bcebfd

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171

7272
- `Selected`
7373
- `SelectError`
74-
- `SelectErrorGroup`
7574
- `UnhandledSelectedError`
7675
- `select`
7776
- `selected_from`
@@ -110,6 +109,8 @@
110109

111110
This was removed alongside `Peekable` (it was only raised when using a `Receiver` that was converted into a `Peekable`).
112111

112+
* `SelectErrorGroup` was removed, a Python built-in `BaseExceptionGroup` is raised instead in case of unexpected errors while finalizing a `select()` loop, which will be automatically converted to a simple `ExceptionGroup` when no exception in the groups is a `BaseException`.
113+
113114
- `Timer`:
114115

115116
- `periodic()` and `timeout()`: The names proved to be too confusing, please use `Timer()` and pass a missing ticks policy explicitly instead. In general you can update your code by doing:

src/frequenz/channels/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
* [SelectError][frequenz.channels.SelectError]: Base class for all errors
5959
related to [select][frequenz.channels.select].
6060
61-
* [SelectErrorGroup][frequenz.channels.SelectErrorGroup]: A group of errors
62-
raised by [select][frequenz.channels.select].
63-
6461
* [UnhandledSelectedError][frequenz.channels.UnhandledSelectedError]: An error
6562
raised by [select][frequenz.channels.select] that was not handled by the
6663
user.
@@ -85,7 +82,6 @@
8582
from ._select import (
8683
Selected,
8784
SelectError,
88-
SelectErrorGroup,
8985
UnhandledSelectedError,
9086
select,
9187
selected_from,
@@ -103,7 +99,6 @@
10399
"ReceiverError",
104100
"ReceiverStoppedError",
105101
"SelectError",
106-
"SelectErrorGroup",
107102
"Selected",
108103
"Sender",
109104
"SenderError",

src/frequenz/channels/_select.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ class SelectError(Error):
279279
This exception is raised when a `select()` iteration fails. It is raised as
280280
a single exception when one receiver fails during normal operation (while calling
281281
`ready()` for example). It is raised as a group exception
282-
([`SelectErrorGroup`][frequenz.channels.SelectErrorGroup]) when a `select` loop
283-
is cleaning up after it's done.
282+
([`BaseExceptionGroup`][]) when a `select` loop is cleaning up after it's done.
284283
"""
285284

286285

@@ -304,14 +303,6 @@ def __init__(self, selected: Selected[_T]) -> None:
304303
"""The selected receiver that was not handled."""
305304

306305

307-
class SelectErrorGroup(BaseExceptionGroup[BaseException], SelectError):
308-
"""Some receivers stopped with errors while cleaning up a `select()` operation.
309-
310-
The group is composed of the errors raised by the receivers when they are stopped
311-
during the cleanup of a [`select()`][frequenz.channels.select] loop.
312-
"""
313-
314-
315306
# Typing for select() is tricky. We had the idea of using a declarative design for
316307
# select, something like:
317308
#
@@ -426,8 +417,8 @@ async def select(*receivers: Receiver[Any]) -> AsyncIterator[Selected[Any]]:
426417
427418
Raises:
428419
UnhandledSelectedError: If a selected receiver was not handled in the if-chain.
429-
SelectErrorGroup: If there is an error while finishing the select operation and
430-
receivers fail while cleaning up.
420+
BaseExceptionGroup: If there is an error while finishing the select operation
421+
and receivers fail while cleaning up.
431422
SelectError: If there is an error while selecting receivers during normal
432423
operation. For example if a receiver raises an exception in the `ready()`
433424
method. Normal errors while receiving messages are not raised, but reported
@@ -483,7 +474,7 @@ async def _stop_pending_tasks(pending: set[asyncio.Task[bool]]) -> None:
483474
pending: The pending tasks to stop.
484475
485476
Raises:
486-
SelectErrorGroup: If the receivers raise any exceptions.
477+
BaseExceptionGroup: If the receivers raise any exceptions.
487478
"""
488479
if pending:
489480
for task in pending:
@@ -502,4 +493,6 @@ async def _stop_pending_tasks(pending: set[asyncio.Task[bool]]) -> None:
502493
# will be collected by the asyncio loop. This shouldn't be too bad as
503494
# errors produced by receivers will be re-raised when trying to use them
504495
# again.
505-
raise SelectErrorGroup("Some receivers failed when select()ing", exceptions)
496+
raise BaseExceptionGroup(
497+
"Some receivers failed when select()ing", exceptions
498+
)

0 commit comments

Comments
 (0)