borgend/exprotect.py

changeset 106
a7bdc239ef62
equal deleted inserted replaced
105:55043f86c0b5 106:a7bdc239ef62
1 #
2 # Borgend by Tuomo Valkonen, 2018
3 #
4 # Except-catching decocators to catch bugs in callbacks
5 #
6
7 import logging
8
9 logger=logging.getLogger(__name__)
10
11 def protect_noreturn(fn):
12 name=fn.__name__
13 def wrapper(*args, **kwargs):
14 try:
15 fn(*args, **kwargs)
16 except:
17 logger.exception('bug in ' + name)
18 return wrapper
19
20
21 def protect_return(default):
22 def wrap(fn):
23 name=fn.__name__
24 def wrapper(*args, **kwargs):
25 try:
26 return fn(*args, **kwargs)
27 except:
28 logger.exception('bug in ' + name)
29 return default
30 return wrapper
31 return wrap

mercurial