aiq.utils.exception_handlers.schemas#
Attributes#
Functions#
|
A decorator that handles |
|
A decorator that handles YAML parsing exceptions. |
Module Contents#
- logger#
- schema_exception_handler(func, **kwargs)#
A decorator that handles
ValidationError
exceptions for schema validation functions.This decorator wraps a function that performs schema validation using Pydantic. If a
ValidationError
is raised, it logs detailed error messages and raises aValueError
with the combined error messages.Parameters#
- funccallable
The function to be decorated. This function is expected to perform schema validation.
- kwargsdict
Additional keyword arguments to be passed to the function.
Returns#
- callable
The wrapped function that executes
func
with exception handling.
Raises#
- ValueError
If a
ValidationError
is caught, this decorator logs the error details and raises aValueError
with the combined error messages.
Notes#
This decorator is particularly useful for functions that validate configurations or data models, ensuring that any validation errors are logged and communicated clearly.
Examples#
>>> @schema_exception_handler ... def validate_config(config_data): ... schema = MySchema(**config_data) ... return schema ... >>> try: ... validate_config(invalid_config) ... except ValueError as e: ... logger.error("Caught error: %s", e) Caught error: Invalid configuration: field1: value is not a valid integer; field2: field required
- yaml_exception_handler(func)#
A decorator that handles YAML parsing exceptions.
This decorator wraps a function that performs YAML file operations. If a YAML-related error occurs, it logs the error and raises a ValueError with a clear error message.
Returns#
- callable
The wrapped function that executes
func
with YAML exception handling.
Raises#
- ValueError
If a YAML error is caught, with details about the parsing failure.