MCPcopy Create free account
hub / github.com/ipython/traitlets / catch_config_error

Function catch_config_error

traitlets/config/application.py:106–124  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

104
105
106def 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
127class ApplicationError(Exception):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…