Safe decorators
provide.foundation.errors.safe_decorators
¶
TODO: Add module docstring.
Functions¶
log_only_error_context
¶
log_only_error_context(
*,
context_provider: (
Callable[[], dict[str, Any]] | None
) = None,
log_level: str = "debug",
log_success: bool = False
) -> Callable[[F], F]
Safe decorator that only adds logging context without changing error behavior.
This decorator preserves the exact original error message and type while adding structured logging context. It never suppresses errors or changes their behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_provider
|
Callable[[], dict[str, Any]] | None
|
Function that provides additional logging context. |
None
|
log_level
|
str
|
Level for operation logging ('debug', 'trace', etc.) |
'debug'
|
log_success
|
bool
|
Whether to log successful operations. |
False
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function that preserves all original error behavior. |
Examples:
>>> @log_only_error_context(
... context_provider=lambda: {"operation": "detect_launcher_type"},
... log_level="trace"
... )
... def detect_launcher_type(self, path):
... # Original error messages preserved exactly
... return self._internal_detect(path)