0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
posthog/ee/clickhouse/test/test_error.py
Karl-Aksel Puulmann f25ae0a879
Generate clickhouse query error class dynamically (#5492)
This helps with not grouping sentry errors together.

See issue for more context

Closes https://github.com/PostHog/posthog/issues/5491
2021-08-06 16:31:42 +01:00

27 lines
1.1 KiB
Python

import pytest
from clickhouse_driver.errors import ServerException
from ee.clickhouse.errors import wrap_query_error
from posthog.exceptions import EstimatedQueryExecutionTimeTooLong
@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",
"Estimated query execution time (34.5 seconds) is too long.",
None,
),
(ServerException("Syntax error", code=62), "CHQueryErrorSyntaxError", "Code: 62.\nSyntax error", 62),
(ServerException("Syntax error", code=9999), "CHQueryErrorUnknown", "Code: 9999.\nSyntax error", 9999),
],
)
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