Method decorator for catching invalid config (Trait/ArgumentErrors) during init. On a TraitError (generally caused by bad config), this will print the trait's message, and exit the app. For use on init methods, to prevent invoking excepthook on invalid input.
(method: T)
| 104 | |
| 105 | |
| 106 | def catch_config_error(method: T) -> T: |
| 107 | """Method decorator for catching invalid config (Trait/ArgumentErrors) during init. |
| 108 | |
| 109 | On a TraitError (generally caused by bad config), this will print the trait's |
| 110 | message, and exit the app. |
| 111 | |
| 112 | For use on init methods, to prevent invoking excepthook on invalid input. |
| 113 | """ |
| 114 | |
| 115 | @functools.wraps(method) |
| 116 | def inner(app: Application, *args: t.Any, **kwargs: t.Any) -> t.Any: |
| 117 | try: |
| 118 | return method(app, *args, **kwargs) |
| 119 | except (TraitError, ArgumentError) as e: |
| 120 | app.log.fatal("Bad config encountered during initialization: %s", e) |
| 121 | app.log.debug("Config at the time: %s", app.config) |
| 122 | app.exit(1) |
| 123 | |
| 124 | return t.cast(T, inner) |
| 125 | |
| 126 | |
| 127 | class ApplicationError(Exception): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…