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(mysql): map SSH tunnel errors to friendly guidance during validation (#71851)

Tom Owers955856bb2082
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py
index 5109319e9425..54340bdf1c1f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py
@@ -312,10 +312,17 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
try:
self.get_schemas(config, team_id)
except BaseSSHTunnelForwarderError as e:
+ # sshtunnel surfaces raw library strings (e.g. "Could not establish session to SSH
+ # gateway"); map them to the friendly guidance in `get_non_retryable_errors` — which the
+ # generic `except Exception` branch below already applies — instead of leaking the
+ # internal wording to the wizard.
+ ssh_error = e.value or ""
+ for pattern, friendly_error in self.get_non_retryable_errors().items():
+ if friendly_error and pattern in ssh_error:
+ return False, friendly_error
return (
False,
- e.value
- or f"Could not connect to {self.get_source_config.name} via the SSH tunnel. Please check all connection details are valid.",
+ f"Could not connect to {self.get_source_config.name} via the SSH tunnel. Please check all connection details are valid.",
)
except Exception as e:
# Connection/credential failures we already classify as non-retryable during sync
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py
index 6728d9824a9f..a6a0c40fb8d3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py
@@ -6,6 +6,7 @@ import pytest
from unittest.mock import MagicMock
import pymysql
+from sshtunnel import BaseSSHTunnelForwarderError
from posthog.schema import SourceFieldInputConfig
@@ -1843,6 +1844,18 @@ class TestMySQLSourceValidateCredentials:
assert error is not None
capture.assert_called_once()
+ def test_ssh_tunnel_error_is_mapped_not_leaked(self, source, mocker):
+ # sshtunnel's raw "Could not establish session to SSH gateway" must be replaced with the
+ # friendly guidance, not surfaced verbatim to the wizard.
+ raw = "Could not establish session to SSH gateway"
+ mocker.patch.object(source, "get_schemas", side_effect=BaseSSHTunnelForwarderError(raw))
+
+ valid, error = source.validate_credentials(_make_config(), team_id=1)
+
+ assert valid is False
+ assert error != raw
+ assert error == source.get_non_retryable_errors()[raw]
+
class _RaisingTunnel:
"""Context manager whose `__enter__` raises, standing in for paramiko's handshake EOFError."""