Skip to content

Commit 6d31111

Browse files
commands: log command validation errors (#6164)
1 parent 821ecc0 commit 6d31111

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

cylc/flow/network/resolvers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ async def _mutation_mapper(
761761
except Exception as exc:
762762
# NOTE: keep this exception vague to prevent a bad command taking
763763
# down the scheduler
764+
LOG.warning(f'{log1}\n{exc.__class__.__name__}: {exc}')
764765
if cylc.flow.flags.verbosity > 1:
765766
LOG.exception(exc) # log full traceback in debug mode
766767
return (False, str(exc))

tests/integration/test_resolvers.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,59 @@ async def test_command_logging(mock_flow, caplog, log_filter):
250250
await mock_flow.resolvers._mutation_mapper("put_messages", kwargs, meta)
251251
assert log_filter(
252252
caplog, contains='Command "put_messages" received from Dr Spock')
253+
254+
255+
async def test_command_validation_failure(
256+
mock_flow,
257+
caplog,
258+
flow_args,
259+
monkeypatch,
260+
):
261+
"""It should log command validation failures server side."""
262+
caplog.set_level(logging.DEBUG, None)
263+
flow_args['workflows'].append(
264+
{
265+
'user': mock_flow.owner,
266+
'workflow': mock_flow.name,
267+
'workflow_sel': None,
268+
}
269+
)
270+
271+
# submit a command with invalid arguments:
272+
async def submit_invalid_command(verbosity=0):
273+
nonlocal caplog, mock_flow, flow_args
274+
monkeypatch.setattr('cylc.flow.flags.verbosity', verbosity)
275+
caplog.clear()
276+
return await mock_flow.resolvers.mutator(
277+
None,
278+
'stop',
279+
flow_args,
280+
{'task': 'cycle/task/job', 'mode': 'not-a-mode'},
281+
{},
282+
)
283+
284+
# submitting the invalid command should result in this error
285+
msg = 'This command does not take job ids:\n * cycle/task/job'
286+
287+
# test submitting the command at *default* verbosity
288+
response = await submit_invalid_command()
289+
290+
# the error should be sent back to the client:
291+
assert response[0]['response'][1] == msg
292+
# it should also be logged by the server:
293+
assert caplog.records[-1].levelno == logging.WARNING
294+
assert msg in caplog.records[-1].message
295+
296+
# test submitting the command at *debug* verbosity
297+
response = await submit_invalid_command(verbosity=2)
298+
299+
# the error should be sent back to the client:
300+
assert response[0]['response'][1] == msg
301+
# it should be logged at the server
302+
assert caplog.records[-2].levelno == logging.WARNING
303+
assert msg in caplog.records[-2].message
304+
# the traceback should also be logged
305+
# (note traceback gets logged at the ERROR level and shows up funny in
306+
# caplog)
307+
assert caplog.records[-1].levelno == logging.ERROR
308+
assert msg in caplog.records[-1].message

0 commit comments

Comments
 (0)