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(google-analytics): drop raw JSON parser text from custom reports error (#91479)

Tom Owers75fe23835510
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/settings.py
index 5e4789b6d0d4..a795835f55b3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/settings.py
@@ -214,7 +214,9 @@ def parse_custom_reports(custom_reports_json: str | None) -> dict[str, GoogleAna
try:
parsed = json.loads(custom_reports_json)
except json.JSONDecodeError as e:
- raise CustomReportError(f"Custom reports must be valid JSON: {e}.") from e
+ raise CustomReportError(
+ "Custom reports must be valid JSON. Provide a JSON array of report objects, then try again."
+ ) from e
if not isinstance(parsed, list):
raise CustomReportError("Custom reports must be a JSON array of report objects.")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py
index 5b62741cbf99..9688402c70a5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py
@@ -127,6 +127,20 @@ def test_parse_custom_reports_rejects_invalid(custom_reports, expected_substring
assert expected_substring in str(exc.value)
+def test_parse_custom_reports_invalid_json_hides_parser_detail():
+ # The raw JSONDecodeError text (e.g. "Expecting value: line 1 column 1 (char 0)") is debug
+ # noise for the user pasting a report, so the message stays actionable without echoing any
+ # of it back. Asserting the exact message (rather than just the absence of "column"/"char")
+ # also catches other JSONDecodeError wording, like "Expecting value", being reintroduced.
+ with pytest.raises(CustomReportError) as exc:
+ parse_custom_reports("not json")
+ message = str(exc.value)
+ assert message == "Custom reports must be valid JSON. Provide a JSON array of report objects, then try again."
+ assert "column" not in message
+ assert "char" not in message
+ assert "Expecting value" not in message
+
+
def test_validate_credentials_rejects_invalid_custom_reports():
# A malformed custom-report config is surfaced at setup, before any GA4 call, so the
# user fixes their JSON instead of hitting an opaque runReport failure mid-sync.