From: Matthijs Kooijman Date: Sat, 7 Aug 2010 18:48:53 +0000 (+0200) Subject: handlers: Add fail_on_exception handler. X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fprojects%2Fbackupninja.git;a=commitdiff_plain;h=96f1913c89c0d934c9b75ff9fae2c0eda44e4823 handlers: Add fail_on_exception handler. This decorator is meant for methods on Action subclasses and records failure when the decorated method throws an exception. --- diff --git a/src/lib/backupninja/handlers/__init__.py b/src/lib/backupninja/handlers/__init__.py index dbc403e..29dc756 100644 --- a/src/lib/backupninja/handlers/__init__.py +++ b/src/lib/backupninja/handlers/__init__.py @@ -24,6 +24,20 @@ import logging as log from backupninja import config +def fail_on_exception(f): + """ + This is a decorator meant for methods on the Action class. It + catches any exceptions thrown, sets the failed attribute to True and + rethrows the exception. + """ + def inner(self, *args, **kwargs): + try: + f(self, *args, **kwargs) + except: + self.failed = True + raise + return inner + class Action(object): """ Subclasses of Action represent handlers for various action types.