Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/grpclib/exceptions.py: 60%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1from typing import Optional, Any 

2 

3from .const import Status 

4 

5 

6class GRPCError(Exception): 

7 """Expected error, may be raised during RPC call 

8 

9 There can be multiple origins of this error. It can be generated 

10 on the server-side and on the client-side. If this error originates from 

11 the server, on the wire this error is represented as ``grpc-status`` and 

12 ``grpc-message`` trailers. Possible values of the ``grpc-status`` trailer 

13 are described in the gRPC protocol definition. In ``grpclib`` these values 

14 are represented as :py:class:`~grpclib.const.Status` enum. 

15 

16 Here are possible origins of this error: 

17 

18 - you may raise this error to cancel current call on the server-side or 

19 return non-OK :py:class:`~grpclib.const.Status` using 

20 :py:meth:`~grpclib.server.Stream.send_trailing_metadata` method 

21 `(e.g. resource not found)` 

22 - server may return non-OK ``grpc-status`` in different failure 

23 conditions `(e.g. invalid request)` 

24 - client raises this error for non-OK ``grpc-status`` from the server 

25 - client may raise this error in different failure conditions 

26 `(e.g. server returned unsupported` ``:content-type`` `header)` 

27 

28 """ 

29 def __init__( 

30 self, 

31 status: Status, 

32 message: Optional[str] = None, 

33 details: Any = None, 

34 ) -> None: 

35 super().__init__(status, message, details) 

36 #: :py:class:`~grpclib.const.Status` of the error 

37 self.status = status 

38 #: Error message 

39 self.message = message 

40 #: Error details 

41 self.details = details 

42 

43 

44class ProtocolError(Exception): 

45 """Unexpected error, raised by ``grpclib`` when your code violates 

46 gRPC protocol 

47 

48 This error means that you probably should fix your code. 

49 """ 

50 

51 

52class StreamTerminatedError(Exception): 

53 """Unexpected error, raised when we receive ``RST_STREAM`` frame from 

54 the other side 

55 

56 This error means that the other side decided to forcefully cancel current 

57 call, probably because of a protocol error. 

58 """