Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(clickhouse): point wizard connection errors at the field to fix (#106598)

Tom Owersd2c4b3942efb
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
index 61da18de99c8..11912f5f7a88 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
@@ -91,18 +91,21 @@ _INVALID_CREDENTIALS = (
"The database rejected the username or password. Check the user and password for this source and try again."
)
+_HOST_NOT_RESOLVED = "Host could not be resolved. Check the host is spelled correctly and reachable from PostHog."
+
# Error message → user-friendly translation. Matched as a substring of the
# exception string. Patterns are lowercase-matched.
ClickHouseErrors: dict[str, str] = {
"authentication failed": _INVALID_CREDENTIALS,
"code: 516": _INVALID_CREDENTIALS, # AUTHENTICATION_FAILED
"code: 81": "Database does not exist. Check the database name is correct.", # UNKNOWN_DATABASE
- "code: 60": "Table does not exist", # UNKNOWN_TABLE
- "code: 192": "Permission denied on the requested database or table", # UNKNOWN_USER
- "code: 497": "Permission denied on the requested database or table", # ACCESS_DENIED
- "nodename nor servname provided": "Could not resolve the ClickHouse host",
- "name or service not known": "Could not resolve the ClickHouse host",
- "connection refused": "Could not connect to ClickHouse on the given host/port",
+ "code: 60": "Table does not exist. Check the table still exists in your ClickHouse database.", # UNKNOWN_TABLE
+ "code: 192": _INVALID_CREDENTIALS, # UNKNOWN_USER
+ "code: 497": "Your ClickHouse user doesn't have permission to read this database. Grant the user SELECT on the database, then try again.", # ACCESS_DENIED
+ # Same wording as the MySQL source, so a wrong host or port reads the same across databases.
+ "nodename nor servname provided": _HOST_NOT_RESOLVED,
+ "name or service not known": _HOST_NOT_RESOLVED,
+ "connection refused": "Could not connect to the host on the port given. Check the host and port are correct and the ClickHouse server is accepting connections.",
"connection timed out": "Connection to ClickHouse timed out. Check that your database is reachable from the public internet and that PostHog's egress IP addresses are allowed through your firewall (see the docs). For a database that can't be exposed publicly, use the SSH tunnel option.",
# Must stay above the generic "ssl" entry, which would otherwise match first and send the
# user to the wrong toggle. Verification runs against the configured ClickHouse host even
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
index 7e951254b6f8..7dd503c75809 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
@@ -1018,8 +1018,14 @@ class TestGetClientSessionSettings:
class TestTranslateError:
- def test_matches_substring_inside_long_error(self):
- msg = "Code: 516. DB::Exception: Authentication failed for user 'default'"
+ @pytest.mark.parametrize(
+ "msg",
+ [
+ "Code: 516. DB::Exception: Authentication failed for user 'default'",
+ "Code: 192. DB::Exception: There is no user `analytics` in user directories. (UNKNOWN_USER)",
+ ],
+ )
+ def test_rejected_login_maps_to_invalid_credentials(self, msg):
translated = ClickHouseSource._translate_error(msg)
assert translated is not None
assert "rejected the username or password" in translated