Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/_core/_exceptions.py: 73%
26 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:19 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:19 +0000
1from __future__ import annotations
3from traceback import format_exception
6class BrokenResourceError(Exception):
7 """
8 Raised when trying to use a resource that has been rendered unusable due to external causes
9 (e.g. a send stream whose peer has disconnected).
10 """
13class BrokenWorkerProcess(Exception):
14 """
15 Raised by :func:`run_sync_in_process` if the worker process terminates abruptly or otherwise
16 misbehaves.
17 """
20class BusyResourceError(Exception):
21 """Raised when two tasks are trying to read from or write to the same resource concurrently."""
23 def __init__(self, action: str):
24 super().__init__(f"Another task is already {action} this resource")
27class ClosedResourceError(Exception):
28 """Raised when trying to use a resource that has been closed."""
31class DelimiterNotFound(Exception):
32 """
33 Raised during :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_until` if the
34 maximum number of bytes has been read without the delimiter being found.
35 """
37 def __init__(self, max_bytes: int) -> None:
38 super().__init__(
39 f"The delimiter was not found among the first {max_bytes} bytes"
40 )
43class EndOfStream(Exception):
44 """Raised when trying to read from a stream that has been closed from the other end."""
47class ExceptionGroup(BaseException):
48 """
49 Raised when multiple exceptions have been raised in a task group.
51 :var ~typing.Sequence[BaseException] exceptions: the sequence of exceptions raised together
52 """
54 SEPARATOR = "----------------------------\n"
56 exceptions: list[BaseException]
58 def __str__(self) -> str:
59 tracebacks = [
60 "".join(format_exception(type(exc), exc, exc.__traceback__))
61 for exc in self.exceptions
62 ]
63 return (
64 f"{len(self.exceptions)} exceptions were raised in the task group:\n"
65 f"{self.SEPARATOR}{self.SEPARATOR.join(tracebacks)}"
66 )
68 def __repr__(self) -> str:
69 exception_reprs = ", ".join(repr(exc) for exc in self.exceptions)
70 return f"<{self.__class__.__name__}: {exception_reprs}>"
73class IncompleteRead(Exception):
74 """
75 Raised during :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_exactly` or
76 :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_until` if the
77 connection is closed before the requested amount of bytes has been read.
78 """
80 def __init__(self) -> None:
81 super().__init__(
82 "The stream was closed before the read operation could be completed"
83 )
86class TypedAttributeLookupError(LookupError):
87 """
88 Raised by :meth:`~anyio.TypedAttributeProvider.extra` when the given typed attribute is not
89 found and no default value has been given.
90 """
93class WouldBlock(Exception):
94 """Raised by ``X_nowait`` functions if ``X()`` would block."""