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): surface plain-English custom manifest validation errors (#64473)

Tom Owers389d383a5905
diff --git a/posthog/temporal/data_imports/sources/custom/source.py b/posthog/temporal/data_imports/sources/custom/source.py
index b0d527fdf55e..779e8b4e73b5 100644
--- a/posthog/temporal/data_imports/sources/custom/source.py
+++ b/posthog/temporal/data_imports/sources/custom/source.py
@@ -276,12 +276,38 @@ def _validate_incremental_configs(manifest: dict[str, Any]) -> None:
)
+# Plain-English replacements for the pydantic constraint messages users hit most
+# when hand-authoring a manifest; an unmapped error keeps pydantic's own wording.
+_VALIDATION_MESSAGE_OVERRIDES = {
+ "string_too_short": "must not be empty",
+}
+
+
+def _render_error_location(loc: tuple[Any, ...]) -> str:
+ """Render a pydantic ``loc`` tuple as a path that mirrors the manifest JSON,
+ e.g. ``("resources", 0, "endpoint", "path")`` -> ``resources[0].endpoint.path``."""
+ rendered = ""
+ for part in loc:
+ if isinstance(part, int):
+ rendered += f"[{part}]"
+ elif rendered:
+ rendered += f".{part}"
+ else:
+ rendered = str(part)
+ return rendered
+
+
def _format_validation_errors(exc: ValidationError) -> str:
- """Render Pydantic's validation errors as a single user-facing string."""
+ """Render Pydantic's validation errors as a single user-facing string.
+
+ Pydantic's positional loc tuples and raw constraint wording ("String should
+ have at least 1 character") read like internals to someone editing manifest
+ JSON, so mirror the JSON path and swap the common messages for plainer English.
+ """
messages: list[str] = []
for error in exc.errors():
- location = ".".join(str(part) for part in error["loc"])
- message = error["msg"].removeprefix("Value error, ")
+ location = _render_error_location(error["loc"])
+ message = _VALIDATION_MESSAGE_OVERRIDES.get(error["type"], error["msg"].removeprefix("Value error, "))
messages.append(f"{location}: {message}" if location else message)
return "; ".join(messages)
diff --git a/posthog/temporal/data_imports/sources/custom/test_custom_source.py b/posthog/temporal/data_imports/sources/custom/test_custom_source.py
index 5d445884a76e..7e8fc664aeb7 100644
--- a/posthog/temporal/data_imports/sources/custom/test_custom_source.py
+++ b/posthog/temporal/data_imports/sources/custom/test_custom_source.py
@@ -84,6 +84,17 @@ class TestValidateManifest(SimpleTestCase):
validate_manifest(manifest)
assert expected_substring in str(ctx.exception)
+ def test_empty_required_strings_give_plain_message(self):
+ # Empty required fields used to surface pydantic's raw "String should have at
+ # least 1 character" with positional paths; assert the friendlier, JSON-mirroring form.
+ manifest = {"client": {"base_url": ""}, "resources": [{"name": "", "endpoint": {"path": ""}}]}
+ with self.assertRaises(ManifestValidationError) as ctx:
+ validate_manifest(manifest)
+ message = str(ctx.exception)
+ assert "client.base_url: must not be empty" in message
+ assert "resources[0].name: must not be empty" in message
+ assert "resources[0].endpoint.path: must not be empty" in message
+
def test_rejects_duplicate_resource_names(self):
manifest = _minimal_manifest()
manifest["resources"].append({**manifest["resources"][0]})