Merge "Make YAQL evaluator catch and wrap all underlying exceptions"

This commit is contained in:
Jenkins 2016-11-18 11:07:42 +00:00 committed by Gerrit Code Review
commit aa8f331349
3 changed files with 43 additions and 4 deletions

View File

@ -55,7 +55,7 @@ class YAQLEvaluator(Evaluator):
result = YAQL_ENGINE(expression).evaluate(
context=expression_utils.get_yaql_context(data_context)
)
except (yaql_exc.YaqlException, KeyError, ValueError, TypeError) as e:
except Exception as e:
raise exc.YaqlEvaluationException(
"Can not evaluate YAQL expression [expression=%s, error=%s"
", data=%s]" % (expression, str(e), data_context)

View File

@ -586,3 +586,39 @@ class ErrorHandlingEngineTest(base.EngineTestCase):
self.assertIsNotNone(state_info)
self.assertTrue(state_info.find('error=') > 0)
self.assertTrue(state_info.find('error=') < state_info.find('action='))
def test_publish_bad_yaql(self):
wf_text = """---
version: '2.0'
wf:
type: direct
input:
- my_dict:
- id: 1
value: 11
tasks:
task1:
action: std.noop
publish:
problem_var: <% $.my_dict.where($.value = 13).id.first() %>
"""
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]
action_ex = task_ex.action_executions[0]
self.assertEqual(states.SUCCESS, action_ex.state)
self.assertEqual(states.ERROR, task_ex.state)
self.assertIsNotNone(task_ex.state_info)
self.assertEqual(states.ERROR, wf_ex.state)

View File

@ -200,9 +200,12 @@ def publish_variables(task_ex, task_spec):
task_ex.name
)
data = (task_spec.get_publish()
if task_ex.state == states.SUCCESS
else task_spec.get_publish_on_error())
data = (
task_spec.get_publish()
if task_ex.state == states.SUCCESS
else task_spec.get_publish_on_error()
)
task_ex.published = expr.evaluate_recursively(data, expr_ctx)