Exceptions¶
This module contains the patch error taxonomy used across parsing, apply-time conflicts, model validation, and FastAPI integration.
InvalidJSONPointer
¶
Bases: PatchInputError
A JSON Pointer definition or instance is invalid.
Examples:
- Pointer string is malformed or uses an incompatible backend.
- Pointer backend class fails protocol checks.
Typical HTTP mapping
422 Unprocessable Entity for request input.
Source code in jsonpatchx/exceptions.py
InvalidOperationDefinition
¶
Bases: PatchError
An OperationSchema definition is invalid (developer error).
Examples:
opis missing or not declared asLiteral[...].opis declared as a ClassVar, so it is not a model field.
Source code in jsonpatchx/exceptions.py
InvalidOperationRegistry
¶
Bases: PatchError
An OperationRegistry has incompatible OperationSchemas (developer error).
Examples:
- Duplicate
opidentifiers across schemas. - Non-OperationSchema classes provided to the registry.
Source code in jsonpatchx/exceptions.py
OperationNotRecognized
¶
Bases: PatchInputError
An OperationSchema instance does not belong to the active registry.
Examples:
- Passing a StandardRegistry op instance into a custom registry.
Typical HTTP mapping
422 Unprocessable Entity.
Source code in jsonpatchx/exceptions.py
OperationValidationError
¶
Bases: PatchInputError
An OperationSchema instance failed validation (client error).
Examples:
- Swap operation rejects parent/child pointers via a model validator.
- Operation fields violate custom constraints in validators.
Typical HTTP mapping
422 Unprocessable Entity.
Source code in jsonpatchx/exceptions.py
PatchConflictError
¶
Bases: PatchError
A JSON Patch failed due to a conflict with the current document state.
Examples:
- Path does not exist or array index is out of range.
- Removing a value at a missing or invalid path.
Typical HTTP mapping
409 Conflict (some APIs may prefer 422).
Source code in jsonpatchx/exceptions.py
PatchError
¶
Bases: Exception
Base class for JSON Patch errors.
This type is not raised directly; it anchors the error hierarchy for tooling and API error mapping.
PatchFailureDetail
dataclass
¶
Structured failure details for patch application.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
0-based index of the operation within the patch document. |
op |
OperationSchema
|
Best-effort JSON-serializable representation of the failing operation. For OperationSchema instances, this is model_dump(mode="json", by_alias=True). For mapping-like inputs, this is dict(op). As a last resort, {"repr": repr(op)}. |
message |
str
|
Human-readable error message. |
cause_type |
str | None
|
The exception class name of the underlying cause (useful for logging / API error mapping). |
Source code in jsonpatchx/exceptions.py
PatchInputError
¶
Bases: PatchError
Patch input is invalid or fails validation.
Examples:
- Invalid JSON Pointer syntax in an incoming operation.
- Operation-specific validation failure (e.g., swap parent/child paths).
- Model revalidation fails after applying a patch.
Typical HTTP mapping
422 Unprocessable Entity.
Source code in jsonpatchx/exceptions.py
PatchInternalError
¶
Bases: PatchError
Unexpected exception during patch execution wrapped with structured context.
This is meant for API layers and debuggability
- points at the exact op index
- includes the full op payload (best-effort JSON shape)
Example
A ZeroDivisionError raised inside a custom op implementation that fails to catch it.
Typical HTTP mapping
500 Internal Server Error (unexpected failure).
Source code in jsonpatchx/exceptions.py
PatchValidationError
¶
Bases: PatchInputError
Patched data failed validation against a target schema.
Examples:
- Model-aware patching produces a document that violates the target model.
Typical HTTP mapping
422 Unprocessable Entity.
Source code in jsonpatchx/exceptions.py
TestOpFailed
¶
Bases: PatchConflictError
A test operation failed (RFC 6902).
Typical HTTP mapping
409 Conflict (state mismatch).