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(data-warehouse): show a friendly error when schema discovery times out (#64227)

Tom Owersdead996ddfdc
diff --git a/posthog/temporal/data_imports/sources/stripe/source.py b/posthog/temporal/data_imports/sources/stripe/source.py
index cf50232c80cf..3067adf90717 100644
--- a/posthog/temporal/data_imports/sources/stripe/source.py
+++ b/posthog/temporal/data_imports/sources/stripe/source.py
@@ -361,6 +361,16 @@ If automatic creation failed due to a permissions error and you're using a restr
if e.missing_permissions:
message += f". Additionally lacks permissions for {', '.join(e.missing_permissions.keys())}"
return False, message
+ except ValueError as e:
+ # `_get_api_key` raises ValueError for deterministic config problems (missing API key,
+ # missing integration ID, missing access token). The user-facing wording already lives
+ # in `get_non_retryable_errors`; reuse it so this path doesn't leak the internal
+ # "Missing Stripe integration ID" string. Fall back to the raw message if unmapped.
+ raw = str(e)
+ for pattern, friendly in self.get_non_retryable_errors().items():
+ if friendly and pattern in raw:
+ return False, friendly
+ return False, raw
except Exception as e:
return False, str(e)
diff --git a/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
index 3637043b1695..7d7fd1faa10c 100644
--- a/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
+++ b/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
@@ -1,5 +1,6 @@
import pytest
+from posthog.temporal.data_imports.sources.generated_configs import StripeAuthMethodConfig, StripeSourceConfig
from posthog.temporal.data_imports.sources.stripe.source import StripeSource
@@ -38,3 +39,25 @@ class TestStripeSource:
def test_non_retryable_errors_do_not_match_transient(self, other_error):
non_retryable_errors = self.source.get_non_retryable_errors()
assert not any(key in other_error for key in non_retryable_errors)
+
+ @pytest.mark.parametrize(
+ "config,expected_message",
+ [
+ # OAuth selected but the integration was never linked (or was deleted): `_get_api_key`
+ # raises ValueError("Missing Stripe integration ID"), an internal string the user can't
+ # act on. validate_credentials must translate it to the reconnect guidance.
+ (
+ StripeSourceConfig(auth_method=StripeAuthMethodConfig(selection="oauth", stripe_integration_id=None)),
+ "Stripe integration ID is not configured. Please reconnect your Stripe account.",
+ ),
+ (
+ StripeSourceConfig(auth_method=StripeAuthMethodConfig(selection="api_key", stripe_secret_key=None)),
+ "Stripe API key is not configured. Please update the source configuration.",
+ ),
+ ],
+ )
+ def test_validate_credentials_missing_config_returns_friendly_message(self, config, expected_message):
+ ok, message = self.source.validate_credentials(config, team_id=1)
+
+ assert ok is False
+ assert message == expected_message
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index 9be8a7828d87..407c65cfae79 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -1450,12 +1450,23 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
actions.setDatabaseSchemas(schemas)
actions.onNext()
} catch (e: any) {
- const errorMessage = e.data?.message ?? e.message
+ // A gateway timeout / 5xx has no JSON body, so e.message is the raw
+ // "Non-OK response [POST ...] (status 504: )" — meaningless to the user. Surface a
+ // friendly hint for server-side failures while keeping any API-provided message.
+ const apiMessage = e.data?.message ?? e.detail
+ const errorMessage =
+ apiMessage ??
+ (e.status >= 500
+ ? 'PostHog could not validate your connection in time. This can happen with a very large schema or a slow or unreachable database — please check your connection details and try again.'
+ : e.message)
lemonToast.error(errorMessage)
posthog.capture('warehouse credentials invalid', {
sourceType: values.selectedConnector.name,
errorMessage,
+ // Keep the raw error (status code etc.) so server-side failures stay triageable.
+ rawError: e.message,
+ status: e.status,
})
}