Coverage for src/lilbee/server/validation_format.py: 100%
6 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-14 11:46 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-14 11:46 +0000
1"""Shared rendering of Litestar body-validation failures for wire envelopes."""
3from __future__ import annotations
5from litestar.exceptions import ValidationException
8def format_validation(exc: ValidationException) -> str:
9 """Render a litestar/pydantic ValidationException as one user-facing string.
11 Litestar wraps pydantic errors as ``{"key": "field_name", "message": "..."}``
12 entries on ``exc.extra``; they flatten into a semicolon-joined string so the
13 error envelope carries the same field names a client expects to see.
14 """
15 items: list[dict[str, str]] = exc.extra if isinstance(exc.extra, list) else []
16 parts = [f"{err.get('key') or ''}: {err.get('message', '')}".lstrip(": ") for err in items]
17 return "; ".join(parts) if parts else str(exc.detail)