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
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from typing import Any
3from ..errors import PrismaError
4from ..http_abstract import AbstractResponse
6__all__ = (
7 'EngineError',
8 'BinaryNotFoundError',
9 'MismatchedVersionsError',
10 'EngineConnectionError',
11 'EngineRequestError',
12 'AlreadyConnectedError',
13 'NotConnectedError',
14 'UnprocessableEntityError',
15)
18_AnyResponse = AbstractResponse[Any]
21class EngineError(PrismaError):
22 pass
25class BinaryNotFoundError(EngineError):
26 pass
29class AlreadyConnectedError(EngineError):
30 pass
33class NotConnectedError(EngineError):
34 pass
37class MismatchedVersionsError(EngineError):
38 got: str
39 expected: str
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
51class EngineConnectionError(EngineError):
52 pass
55class EngineRequestError(EngineError):
56 response: _AnyResponse
58 def __init__(self, response: _AnyResponse, body: str):
59 self.response = response
61 # TODO: better error message
62 super().__init__(f'{response.status}: {body}')
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 )