mirror of
https://github.com/element-hq/synapse.git
synced 2026-10-25 01:53:21 +00:00
Fixes #20309. For endpoints that validate the request body with Pydantic, a validation failure put Pydantic's raw verbose error text into the `error` field of the standard error response, e.g.: ```json { "errcode": "M_MISSING_PARAM", "error": "1 validation error for PutBody\\nroom_id\\n Field required [type=missing, input_value={}, input_type=dict]\\n For further information visit https://errors.pydantic.dev/2.12/v/missing" } ``` This leaks internal details clients cannot act upon (model class names, raw input values, pydantic.dev URLs). This PR adds a `_format_pydantic_error` helper in `synapse/http/servlet.py` that builds a short client-friendly message from the structured `ValidationError.errors()` data instead of `str(e)`: - `{}` against a model requiring `room_id` -> `Missing required field 'room_id'.` - `{"room_id": 123}` -> `'room_id': Input should be a valid string.` - nested models use dotted paths, e.g. `Missing required field 'put.room_id'.` - multiple errors are joined: `Missing required field 'name'; Missing required field 'put'.` The `errcode` selection logic (`M_MISSING_PARAM` / `M_INVALID_PARAM` / `M_BAD_JSON`) is unchanged.