Skip to content

Commit 350e08f

Browse files
models: Change TypeError to ValueError in validation logic
- Updated `_internal.py` to raise `ValueError` instead of `TypeError` for credential validation errors, ensuring compliance with Pydantic error handling best practices. - Documented this change in AGENTS.md to guide contributors on proper error types for validators. Assisted-by: Codex
1 parent 07e831b commit 350e08f

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
- Avoid `@field_validator` on payload models. Prefer existing `BeforeValidator`
7272
helpers (e.g., `_allowed_mime_types`) so validation remains declarative and
7373
consistent across schemas.
74+
- In Pydantic validators, raise `ValueError`/`AssertionError` (or
75+
`PydanticCustomError` when needed), not `TypeError`, so callers consistently
76+
receive `ValidationError` surfaces.
7477
- Keep user-facing `PdfRestClient` and `AsyncPdfRestClient` endpoint helpers
7578
thin: they should primarily assemble payload dicts and delegate validation to
7679
payload models (`model_validate`). Avoid duplicating payload validation in

src/pdfrest/models/_internal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ def _normalize_credentials(cls, data: Any) -> Any:
16331633
"credentials must be a mapping with either pfx/passphrase or "
16341634
"certificate/private_key."
16351635
)
1636-
raise TypeError(msg)
1636+
raise ValueError(msg) # noqa: TRY004
16371637

16381638
normalized: dict[str, Any] = {str(key): value for key, value in payload.items()}
16391639
credential_map = cast(Mapping[object, Any], credentials)

0 commit comments

Comments
 (0)