Fix error message format for task run and continue

* Error message format is fixed so that an error goes before
  other contextual information

Change-Id: Ic8deed8679c6631fd0b797b46715e012033c7db4
This commit is contained in:
Renat Akhmerov 2016-11-10 14:32:08 +07:00
parent 66c049d678
commit 07039d3ab3
4 changed files with 66 additions and 8 deletions

View File

@ -61,8 +61,8 @@ def run_task(wf_cmd):
task_spec = wf_cmd.task_spec
msg = (
"Failed to run task [wf=%s, task=%s]: %s\n%s" %
(wf_ex, task_spec.get_name(), e, tb.format_exc())
"Failed to run task [error=%s, wf=%s, task=%s]:\n%s" %
(e, wf_ex, task_spec.get_name(), tb.format_exc())
)
LOG.error(msg)
@ -158,8 +158,8 @@ def continue_task(task_ex):
wf_ex = task_ex.workflow_execution
msg = (
"Failed to run task [wf=%s, task=%s]: %s\n%s" %
(wf_ex, task_ex.name, e, tb.format_exc())
"Failed to run task [error=%s, wf=%s, task=%s]:\n%s" %
(e, wf_ex, task_ex.name, tb.format_exc())
)
LOG.error(msg)

View File

@ -44,6 +44,8 @@ class YAQLEvaluator(Evaluator):
@classmethod
def evaluate(cls, expression, data_context):
expression = expression.strip() if expression else expression
LOG.debug(
"Evaluating YAQL expression [expression='%s', context=%s]"
% (expression, data_context)
@ -55,8 +57,8 @@ class YAQLEvaluator(Evaluator):
)
except (yaql_exc.YaqlException, KeyError, ValueError, TypeError) as e:
raise exc.YaqlEvaluationException(
"Can not evaluate YAQL expression: %s, error=%s, data = %s"
% (expression, str(e), data_context)
"Can not evaluate YAQL expression [expression=%s, error=%s"
", data=%s]" % (expression, str(e), data_context)
)
LOG.debug("YAQL expression result: %s" % result)

View File

@ -400,7 +400,7 @@ class DirectWorkflowEngineTest(base.EngineTestCase):
wf_ex = self.engine.start_workflow('wf', None)
self.assertIn(
"Can not evaluate YAQL expression: wrong(yaql)",
"Can not evaluate YAQL expression [expression=wrong(yaql)",
wf_ex.state_info
)
self.assertEqual(states.ERROR, wf_ex.state)

View File

@ -417,4 +417,60 @@ class ErrorHandlingEngineTest(base.EngineTestCase):
state_info = task_ex.state_info
self.assertIsNotNone(state_info)
self.assertTrue(state_info.find('error') < state_info.find('data'))
self.assertTrue(state_info.find('error=') > 0)
self.assertTrue(state_info.find('error=') < state_info.find('data='))
def test_error_message_format_invalid_on_task_run(self):
wf_text = """
version: '2.0'
wf:
tasks:
task1:
action: std.echo output={{ _.invalid_var }}
"""
wf_service.create_workflows(wf_text)
wf_ex = self.engine.start_workflow('wf', {})
self.await_workflow_error(wf_ex.id)
with db_api.transaction():
wf_ex = db_api.get_workflow_execution(wf_ex.id)
task_ex = wf_ex.task_executions[0]
state_info = task_ex.state_info
self.assertIsNotNone(state_info)
self.assertTrue(state_info.find('error=') > 0)
self.assertTrue(state_info.find('error=') < state_info.find('wf='))
def test_error_message_format_on_task_continue(self):
wf_text = """
version: '2.0'
wf:
tasks:
task1:
action: std.echo output={{ _.invalid_var }}
wait-before: 1
"""
wf_service.create_workflows(wf_text)
wf_ex = self.engine.start_workflow('wf', {})
self.await_workflow_error(wf_ex.id)
with db_api.transaction():
wf_ex = db_api.get_workflow_execution(wf_ex.id)
task_ex = wf_ex.task_executions[0]
state_info = task_ex.state_info
self.assertIsNotNone(state_info)
self.assertTrue(state_info.find('error=') > 0)
self.assertTrue(state_info.find('error=') < state_info.find('wf='))