From 1f191c3ce164a8b7cbc6d68cd14d240f522a91c7 Mon Sep 17 00:00:00 2001 From: bendikro Date: Sun, 1 May 2016 22:14:46 +0200 Subject: [PATCH] [Base] Fix incorrect use of defer.fail in component --- deluge/component.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/deluge/component.py b/deluge/component.py index e9c7ea799..107d3f00d 100644 --- a/deluge/component.py +++ b/deluge/component.py @@ -8,6 +8,7 @@ # import logging +import traceback from collections import defaultdict from twisted.internet import reactor @@ -21,6 +22,17 @@ class ComponentAlreadyRegistered(Exception): pass +class ComponentException(Exception): + + def __init__(self, message, tb): + super(ComponentException, self).__init__(message) + self.tb = tb + + def __str__(self): + s = super(ComponentException, self).__str__() + return "%s\n%s" % (s, "".join(self.tb)) + + class Component(object): """ Component objects are singletons managed by the :class:`ComponentRegistry`. @@ -112,8 +124,8 @@ class Component(object): elif self._component_state == "Started": d = succeed(True) else: - d = fail("Cannot start a component not in a Stopped state!") - + d = fail(ComponentException("Trying to start a component ('%s') not in stopped state. Current state: '%s'" % + (self._component_name, self._component_state), traceback.format_stack(limit=4))) return d def _component_stop(self): @@ -157,8 +169,8 @@ class Component(object): elif self._component_state == "Paused": d = succeed(None) else: - d = fail("Cannot pause a component in a non-Started state!") - + d = fail(ComponentException("Trying to pause a component ('%s') not in started state. Current state: '%s'" % + (self._component_name, self._component_state), traceback.format_stack(limit=4))) return d def _component_resume(self): @@ -169,8 +181,8 @@ class Component(object): d = maybeDeferred(self._component_start_timer) d.addCallback(on_resume) else: - d = fail("Component cannot be resumed from a non-Paused state!") - + d = fail(ComponentException("Trying to resume a component ('%s') not in paused state. Current state: '%s'" % + (self._component_name, self._component_state), traceback.format_stack(limit=4))) return d def _component_shutdown(self):