Skip to content

Commit 6bb90d1

Browse files
authored
Demote invalid event handler error => warning (#6917)
1 parent d872088 commit 6bb90d1

File tree

8 files changed

+42
-61
lines changed

8 files changed

+42
-61
lines changed

changes.d/6197.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Demote errors about invalid task event names to warnings

cylc/flow/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ def _check_task_event_names(self, taskdef: 'TaskDef') -> None:
17611761
taskdef.rtconfig['outputs'],
17621762
)
17631763
if invalid:
1764-
raise WorkflowConfigError(
1764+
LOG.warning(
17651765
"Invalid event name(s) for "
17661766
f"[runtime][{taskdef.name}][events]{setting}: "
17671767
+ ', '.join(sorted(invalid))

tests/functional/events/36-task-event-bad-custom-template.t

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/functional/events/36-task-event-bad-custom-template/flow.cylc

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/functional/events/36-task-event-bad-custom-template/reference.log

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/functional/events/46-task-output-as-event.t

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
. "$(dirname "$0")/test_header"
2121

22-
set_test_number 3
22+
set_test_number 4
2323

2424
init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__'
2525
[scheduling]
@@ -36,11 +36,16 @@ cylc message -- ${CYLC_WORKFLOW_ID} ${CYLC_TASK_JOB} \
3636
lily = lily
3737
iris = iris
3838
[[[events]]]
39-
handler events = rose, lily, iris, warning
39+
handler events = rose, lily, iris, warning, arsenic
40+
# (arsenic is an invalid event)
4041
handlers = echo %(message)s
4142
__FLOW_CONFIG__
4243

43-
run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}"
44+
TEST_NAME="${TEST_NAME_BASE}-validate"
45+
run_ok "$TEST_NAME" cylc validate "${WORKFLOW_NAME}"
46+
47+
dump_std "${TEST_NAME}"
48+
grep_ok 'WARNING - Invalid event name.*arsenic' "${TEST_NAME}.stderr"
4449

4550
workflow_run_ok "${TEST_NAME_BASE}-run" \
4651
cylc play --debug --no-detach "${WORKFLOW_NAME}"

tests/integration/test_config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,29 @@ async def test_invalid_starttask(one_conf, flow, scheduler, start):
671671
with pytest.raises(InputError, match='a///b'):
672672
async with start(schd):
673673
pass
674+
675+
676+
async def test_task_event_bad_custom_template(
677+
flow, validate, scheduler, start, log_filter
678+
):
679+
"""Validation fails if task event handler has a bad custom template.
680+
"""
681+
exception = (
682+
r"bad task event handler template t1: echo %\(rubbish\)s:"
683+
r" KeyError\('rubbish'\)"
684+
)
685+
events = {
686+
'handlers': 'echo %(rubbish)s',
687+
'handler events': 'succeeded'
688+
}
689+
wid = flow({
690+
'scheduling': {'graph': {'R1': 't1'}},
691+
'runtime': {'t1': {'events': events}},
692+
})
693+
with pytest.raises(WorkflowConfigError, match=exception):
694+
validate(wid)
695+
696+
schd = scheduler(wid)
697+
with pytest.raises(WorkflowConfigError, match=exception):
698+
async with start(schd):
699+
pass

tests/unit/test_config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,8 +1791,8 @@ def test_val_wflow_event_names(item, tmp_flow_config, log_filter):
17911791

17921792

17931793
@pytest.mark.parametrize('item', ['handler events', 'mail events'])
1794-
def test_check_task_event_names(item, tmp_flow_config):
1795-
""""Any invalid task handler events raise an error."""
1794+
def test_check_task_event_names(item, tmp_flow_config, log_filter):
1795+
""""Any invalid task handler events are warned about."""
17961796
flow_file = tmp_flow_config('foo', f"""
17971797
[scheduling]
17981798
[[graph]]
@@ -1805,9 +1805,9 @@ def test_check_task_event_names(item, tmp_flow_config):
18051805
[[[outputs]]]
18061806
owl = who
18071807
""")
1808-
with pytest.raises(WorkflowConfigError) as ex_info:
1809-
WorkflowConfig('foo', str(flow_file), ValidateOptions())
1810-
assert str(ex_info.value) == (
1808+
1809+
WorkflowConfig('foo', str(flow_file), ValidateOptions())
1810+
assert log_filter(contains=(
18111811
f"Invalid event name(s) for [runtime][foo][events]{item}: "
18121812
"badger, horse"
1813-
)
1813+
))

0 commit comments

Comments
 (0)