Coverage for src/prisma/engine/errors.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-08-27 18:25 +0000

1from typing import Any 

2 

3from ..errors import PrismaError 

4from ..http_abstract import AbstractResponse 

5 

6__all__ = ( 

7 'EngineError', 

8 'BinaryNotFoundError', 

9 'MismatchedVersionsError', 

10 'EngineConnectionError', 

11 'EngineRequestError', 

12 'AlreadyConnectedError', 

13 'NotConnectedError', 

14 'UnprocessableEntityError', 

15) 

16 

17 

18_AnyResponse = AbstractResponse[Any] 

19 

20 

21class EngineError(PrismaError): 

22 pass 

23 

24 

25class BinaryNotFoundError(EngineError): 

26 pass 

27 

28 

29class AlreadyConnectedError(EngineError): 

30 pass 

31 

32 

33class NotConnectedError(EngineError): 

34 pass 

35 

36 

37class MismatchedVersionsError(EngineError): 

38 got: str 

39 expected: str 

40 

41 def __init__(self, *, expected: str, got: str): 

42 super().__init__( 

43 f'Expected query engine version `{expected}` but got `{got}`.\n' 

44 + 'If this is intentional then please set the PRISMA_PY_DEBUG_GENERATOR environment ' 

45 + 'variable to 1 and try again.' 

46 ) 

47 self.expected = expected 

48 self.got = got 

49 

50 

51class EngineConnectionError(EngineError): 

52 pass 

53 

54 

55class EngineRequestError(EngineError): 

56 response: _AnyResponse 

57 

58 def __init__(self, response: _AnyResponse, body: str): 

59 self.response = response 

60 

61 # TODO: better error message 

62 super().__init__(f'{response.status}: {body}') 

63 

64 

65class UnprocessableEntityError(EngineRequestError): 

66 def __init__(self, response: _AnyResponse): 

67 super().__init__( 

68 response, 

69 ( 

70 'Error occurred, ' 

71 'it is likely that the internal GraphQL query ' 

72 'builder generated a malformed request.\n' 

73 'Please create an issue at https://github.com/RobertCraigie/prisma-client-py/issues' 

74 ), 

75 )