You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: crates/jsonschema-py/README.md
+26-1
Original file line number
Diff line number
Diff line change
@@ -197,7 +197,32 @@ validator.is_valid({
197
197
}) # False
198
198
```
199
199
200
-
## Error Message Masking
200
+
## Error Handling
201
+
202
+
`jsonschema-rs` provides detailed validation errors through the `ValidationError` class, which includes both basic error information and specific details about what caused the validation to fail:
203
+
204
+
```python
205
+
import jsonschema_rs
206
+
207
+
schema = {"type": "string", "maxLength": 5}
208
+
209
+
try:
210
+
jsonschema_rs.validate(schema, "too long")
211
+
except jsonschema_rs.ValidationError as error:
212
+
# Basic error information
213
+
print(error.message) # '"too long" is longer than 5 characters'
214
+
print(error.instance_path) # Location in the instance that failed
215
+
print(error.schema_path) # Location in the schema that failed
print(f"Exceeded maximum length of {error.kind.limit}")
221
+
```
222
+
223
+
For a complete list of all error kinds and their attributes, see the [type definitions file](https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-py/python/jsonschema_rs/__init__.pyi)
224
+
225
+
### Error Message Masking
201
226
202
227
When working with sensitive data, you might want to hide actual values from error messages.
203
228
You can mask instance values in error messages by providing a placeholder:
0 commit comments