From 96f1913c89c0d934c9b75ff9fae2c0eda44e4823 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sat, 7 Aug 2010 20:48:53 +0200 Subject: [PATCH] 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. --- src/lib/backupninja/handlers/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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. -- 2.30.2