: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(google-ads): surface a clean error for INVALID_ARGUMENT at validate time (#75252)
Tom Owersc7a5fca57ffb
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.pyindex cfef634404a7..aae65f98c076 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/source.py@@ -480,4 +480,15 @@ class GoogleAdsSource("Google Ads returned a temporary error while validating your credentials. This is ""usually a transient issue on Google's side — please try again in a moment.",)+ # A gRPC INVALID_ARGUMENT ("Request contains an invalid argument") means Google rejected the+ # request as malformed — most often a customer ID (or MCC manager ID) that isn't a valid+ # account. Its str() is the same raw protobuf dump (with a per-request peer IP) the user+ # can't act on, so surface an actionable prompt instead of leaking it.+ if "INVALID_ARGUMENT" in error_message:+ return (+ False,+ "Google Ads rejected the request as invalid while validating your credentials. Check "+ "that your customer ID (and your manager account ID, if using an MCC) is correct, then "+ "try again.",+ )return False, f"Error validating credentials: {error_message}"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.pyindex ad5152eae15f..279f5d3ba10f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py@@ -446,6 +446,26 @@ class TestValidateCredentials:assert "try again" in (message or "")assert "Internal error encountered" not in (message or "")+ def test_invalid_argument_returns_actionable_message(self):+ # A malformed request surfaces as a raw gRPC INVALID_ARGUMENT dump (with a per-request peer IP)+ # at validate time. Surface a clean, actionable prompt rather than leaking the protobuf dump.+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)+ client = mock.Mock()+ client.get_service.return_value.list_accessible_customers.side_effect = Exception(+ 'status = StatusCode.INVALID_ARGUMENT\n\tdetails = "Request contains an invalid argument."\n\t'+ 'debug_error_string = "peer_address:ipv4:172.217.112.4:443"'+ )+ with mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.google_ads.google_ads.google_ads_client",+ return_value=client,+ ):+ ok, message = GoogleAdsSource().validate_credentials(config, team_id=1)++ assert ok is False+ assert "customer ID" in (message or "")+ assert "172.217.112.4" not in (message or "")+ assert "StatusCode" not in (message or "")+def _google_ads_exception(request_error: int) -> GoogleAdsException:failure = GoogleAdsFailure(