borgend/exprotect.py

Sun, 25 Dec 2022 13:26:18 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 25 Dec 2022 13:26:18 +0200
changeset 147
c42d69c44170
parent 106
a7bdc239ef62
permissions
-rw-r--r--

Prune also needs --glob-archives instead of --prefix

#
# Borgend by Tuomo Valkonen, 2018
#
# Except-catching decocators to catch bugs in callbacks
#

import logging

logger=logging.getLogger(__name__)

def protect_noreturn(fn):
    name=fn.__name__
    def wrapper(*args, **kwargs):
        try:
            fn(*args, **kwargs)
        except:
            logger.exception('bug in ' + name)
    return wrapper


def protect_return(default):
    def wrap(fn):
        name=fn.__name__
        def wrapper(*args, **kwargs):
            try:
                return fn(*args, **kwargs)
            except:
                logger.exception('bug in ' + name)
                return default
        return wrapper
    return wrap

mercurial