From 7c7e52351b61deb6b94b61ce3188ca27b44c3cad Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 8 Jun 2014 20:55:25 -0700 Subject: [PATCH] Increase usefulness of the retry component compile errors Adjust the descriptiveness of the errors raised when a retry atom is used in a flow or as the root item of a to help users understand why the error is raised. Change-Id: Ia3e13382d49e2225d48b2ae875061f92c211093c --- taskflow/engines/action_engine/compiler.py | 14 ++++++++++++-- taskflow/tests/unit/test_action_engine_compile.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/taskflow/engines/action_engine/compiler.py b/taskflow/engines/action_engine/compiler.py index f5c519cc..5a591526 100644 --- a/taskflow/engines/action_engine/compiler.py +++ b/taskflow/engines/action_engine/compiler.py @@ -109,8 +109,18 @@ class _Flattener(object): elif isinstance(item, task.BaseTask): return self._flatten_task elif isinstance(item, retry.Retry): - raise TypeError("Retry controller %s (%s) is used not as a flow " - "parameter" % (item, type(item))) + if len(self._history) == 1: + raise TypeError("Retry controller: %s (%s) must only be used" + " as a flow constructor parameter and not as a" + " root component" % (item, type(item))) + else: + # TODO(harlowja): we should raise this type error earlier + # instead of later since we should do this same check on add() + # calls, this makes the error more visible (instead of waiting + # until compile time). + raise TypeError("Retry controller: %s (%s) must only be used" + " as a flow constructor parameter and not as a" + " flow added component" % (item, type(item))) else: return None diff --git a/taskflow/tests/unit/test_action_engine_compile.py b/taskflow/tests/unit/test_action_engine_compile.py index 57c248e0..82075b04 100644 --- a/taskflow/tests/unit/test_action_engine_compile.py +++ b/taskflow/tests/unit/test_action_engine_compile.py @@ -46,7 +46,7 @@ class PatternCompileTest(test.TestCase): def test_retry(self): r = retry.AlwaysRevert('r1') - msg_regex = "^Retry controller .* is used not as a flow parameter" + msg_regex = "^Retry controller: .* must only be used .*" self.assertRaisesRegexp(TypeError, msg_regex, compiler.PatternCompiler().compile, r)