|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | 8 | from abc import ABC, abstractmethod |
9 | | -from typing import Any, Callable, Generic, Optional, TypeVar |
| 9 | +from typing import Callable, Generic, Optional, TypeVar |
| 10 | + |
| 11 | +from ._exceptions import ReceiverStoppedError |
10 | 12 |
|
11 | 13 | T = TypeVar("T") |
12 | 14 | U = TypeVar("U") |
13 | 15 |
|
14 | 16 |
|
15 | | -class Error(RuntimeError): |
16 | | - """Base error. |
17 | | -
|
18 | | - All exceptions generated by this library inherit from this exception. |
19 | | - """ |
20 | | - |
21 | | - def __init__(self, message: Any): |
22 | | - """Create a ChannelError instance. |
23 | | -
|
24 | | - Args: |
25 | | - message: An error message. |
26 | | - """ |
27 | | - super().__init__(message) |
28 | | - |
29 | | - |
30 | | -class ChannelError(Error): |
31 | | - """An error produced in a channel. |
32 | | -
|
33 | | - All exceptions generated by channels inherit from this exception. |
34 | | - """ |
35 | | - |
36 | | - def __init__(self, message: Any, channel: Any): |
37 | | - """Create a ChannelError instance. |
38 | | -
|
39 | | - Args: |
40 | | - message: An error message. |
41 | | - channel: A reference to the channel that encountered the error. |
42 | | - """ |
43 | | - super().__init__(message) |
44 | | - self.channel: Any = channel |
45 | | - |
46 | | - |
47 | | -class ChannelClosedError(ChannelError): |
48 | | - """Error raised when trying to operate on a closed channel.""" |
49 | | - |
50 | | - def __init__(self, channel: Any): |
51 | | - """Create a `ChannelClosedError` instance. |
52 | | -
|
53 | | - Args: |
54 | | - channel: A reference to the channel that was closed. |
55 | | - """ |
56 | | - super().__init__(f"Channel {channel} was closed", channel) |
57 | | - |
58 | | - |
59 | | -class SenderError(Error, Generic[T]): |
60 | | - """An error produced in a [Sender][frequenz.channels.Sender]. |
61 | | -
|
62 | | - All exceptions generated by senders inherit from this exception. |
63 | | - """ |
64 | | - |
65 | | - def __init__(self, message: Any, sender: Sender[T]): |
66 | | - """Create an instance. |
67 | | -
|
68 | | - Args: |
69 | | - message: An error message. |
70 | | - sender: The [Sender][frequenz.channels.Sender] where the error |
71 | | - happened. |
72 | | - """ |
73 | | - super().__init__(message) |
74 | | - self.sender: Sender[T] = sender |
75 | | - |
76 | | - |
77 | | -class ReceiverError(Error, Generic[T]): |
78 | | - """An error produced in a [Receiver][frequenz.channels.Receiver]. |
79 | | -
|
80 | | - All exceptions generated by receivers inherit from this exception. |
81 | | - """ |
82 | | - |
83 | | - def __init__(self, message: Any, receiver: Receiver[T]): |
84 | | - """Create an instance. |
85 | | -
|
86 | | - Args: |
87 | | - message: An error message. |
88 | | - receiver: The [Receiver][frequenz.channels.Receiver] where the |
89 | | - error happened. |
90 | | - """ |
91 | | - super().__init__(message) |
92 | | - self.receiver: Receiver[T] = receiver |
93 | | - |
94 | | - |
95 | | -class ReceiverStoppedError(ReceiverError[T]): |
96 | | - """The [Receiver][frequenz.channels.Receiver] stopped producing messages.""" |
97 | | - |
98 | | - def __init__(self, receiver: Receiver[T]): |
99 | | - """Create an instance. |
100 | | -
|
101 | | - Args: |
102 | | - receiver: The [Receiver][frequenz.channels.Receiver] where the |
103 | | - error happened. |
104 | | - """ |
105 | | - super().__init__(f"Receiver {receiver} was stopped", receiver) |
106 | | - |
107 | | - |
108 | 17 | class Sender(ABC, Generic[T]): |
109 | 18 | """A channel Sender.""" |
110 | 19 |
|
|
0 commit comments