2021-08-06 17:31:42 +02:00
|
|
|
import pytest
|
|
|
|
from clickhouse_driver.errors import ServerException
|
|
|
|
|
2022-03-22 21:27:11 +01:00
|
|
|
from posthog.errors import wrap_query_error
|
2021-08-06 17:31:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"error,expected_type,expected_message,expected_code",
|
|
|
|
[
|
|
|
|
(AttributeError("Foobar"), "AttributeError", "Foobar", None),
|
|
|
|
(
|
|
|
|
ServerException("Estimated query execution time (34.5 seconds) is too long. Aborting query"),
|
|
|
|
"EstimatedQueryExecutionTimeTooLong",
|
2024-02-01 12:10:00 +01:00
|
|
|
"Estimated query execution time (34.5 seconds) is too long. Try reducing its scope by changing the time range.",
|
2021-08-06 17:31:42 +02:00
|
|
|
None,
|
|
|
|
),
|
2023-10-26 12:38:15 +02:00
|
|
|
(
|
|
|
|
ServerException("Syntax error", code=62),
|
|
|
|
"CHQueryErrorSyntaxError",
|
|
|
|
"Code: 62.\nSyntax error",
|
|
|
|
62,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
ServerException("Syntax error", code=9999),
|
|
|
|
"CHQueryErrorUnknownException",
|
|
|
|
"Code: 9999.\nSyntax error",
|
|
|
|
9999,
|
|
|
|
),
|
2024-01-22 17:50:31 +01:00
|
|
|
(
|
|
|
|
ServerException(
|
|
|
|
"Memory limit (for query) exceeded: would use 42.00 GiB (attempt to allocate chunk of 16757643 bytes), maximum: 42.00 GiB.",
|
|
|
|
code=241,
|
|
|
|
),
|
|
|
|
"CHQueryErrorMemoryLimitExceeded",
|
2024-01-31 11:08:33 +01:00
|
|
|
"Query exceeds memory limits. Try reducing its scope by changing the time range.",
|
2024-01-22 17:50:31 +01:00
|
|
|
241,
|
|
|
|
),
|
2024-04-29 09:35:03 +02:00
|
|
|
(
|
|
|
|
ServerException("Too many simultaneous queries. Maximum: 100.", code=202),
|
|
|
|
"CHQueryErrorTooManySimultaneousQueries",
|
|
|
|
"Code: 202.\nToo many simultaneous queries. Try again later.",
|
|
|
|
202,
|
|
|
|
),
|
2021-08-06 17:31:42 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_wrap_query_error(error, expected_type, expected_message, expected_code):
|
|
|
|
new_error = wrap_query_error(error)
|
|
|
|
assert type(new_error).__name__ == expected_type
|
|
|
|
assert str(new_error) == expected_message
|
|
|
|
assert getattr(new_error, "code", None) == expected_code
|