ClickHouse failures: ClickhouseError, what the server answers a
failed request with, and their SqlError reasons (the
classifyError of Effect's @effect/sql-clickhouse ClickhouseClient).
classify reads the cause's numeric code: 516 is an
AuthenticationError, 497 an AuthorizationError, 36, 60, 62 and 242
SqlSyntaxError and 159 and 469 StatementTimeoutError; every other
failure (an unknown code, a transport error) is the fallback reason,
UnknownError or, while connecting, ConnectionError.
Classes#
Functions#
parse_error#
parse_error(text) -> ClickhouseErrorThe error in a failed response's body.
| Parameter | Type | Description |
|---|---|---|
text | str |
Returns ClickhouseError
def parse_error(text: str) -> ClickhouseError:
"""The error in a failed response's body."""
found = _ERROR.search(text)
if found is None:
return ClickhouseError(text)
return ClickhouseError(found["message"], int(found["code"]), found["type"])classify#
classify(cause, *, message, operation, fallback='unknown') -> SqlErrorReasonThe reason for a failure cause (see the module).
| Parameter | Type | Description |
|---|---|---|
cause | object | |
message | str | |
operation | str | |
fallback | Literal['connection', 'unknown'] = 'unknown' |
Returns SqlErrorReason
def classify(
cause: object,
*,
message: str,
operation: str,
fallback: Literal["connection", "unknown"] = "unknown",
) -> SqlErrorReason:
"""The reason for a failure ``cause`` (see the module)."""
code = _code(cause)
if code == 516:
reason: Callable[..., SqlErrorReason] = AuthenticationError
elif code == 497:
reason = AuthorizationError
elif code in _SYNTAX:
reason = SqlSyntaxError
elif code in _TIMEOUT:
reason = StatementTimeoutError
else:
reason = ConnectionError if fallback == "connection" else UnknownError
return reason(cause=cause, message=message, operation=operation)catch#
catch(message, operation, fallback='unknown') -> Callable[[object], SqlError]Turns a failure into the SqlError of operation.
| Parameter | Type | Description |
|---|---|---|
message | str | |
operation | str | |
fallback | Literal['connection', 'unknown'] = 'unknown' |
Returns Callable[[object], SqlError]
def catch(
message: str, operation: str, fallback: Literal["connection", "unknown"] = "unknown"
) -> Callable[[object], SqlError]:
"""Turns a failure into the ``SqlError`` of ``operation``."""
return lambda cause: SqlError(
reason=classify(cause, message=message, operation=operation, fallback=fallback)
)