Context manager that attaches extra information to exceptions.
(
ctx: Context, param: Parameter | None = None
)
| 118 | |
| 119 | @contextmanager |
| 120 | def augment_usage_errors( |
| 121 | ctx: Context, param: Parameter | None = None |
| 122 | ) -> cabc.Generator[None]: |
| 123 | """Context manager that attaches extra information to exceptions.""" |
| 124 | try: |
| 125 | yield |
| 126 | except BadParameter as e: |
| 127 | if e.ctx is None: |
| 128 | e.ctx = ctx |
| 129 | if param is not None and e.param is None: |
| 130 | e.param = param |
| 131 | raise |
| 132 | except UsageError as e: |
| 133 | if e.ctx is None: |
| 134 | e.ctx = ctx |
| 135 | raise |
| 136 | |
| 137 | |
| 138 | def iter_params_for_processing( |
no outgoing calls
no test coverage detected