Skip to content

Commit

Permalink
main loop: re-raise CylcError as MainLoopPluginException
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Feb 17, 2020
1 parent 63c2a8c commit d9f1106
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
19 changes: 16 additions & 3 deletions cylc/flow/main_loop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
from cylc.flow.exceptions import CylcError, UserInputError


class MainLoopPluginException(Exception):
"""Raised in-place of CylcError exceptions.
Note:
* Not an instace of CylcError as that is used for controlled
shutdown e.g. SchedulerStop.
"""



def load_plugins(config, additional_plugins=None):
"""Load main loop plugins from the suite/global configuration.
Expand Down Expand Up @@ -112,10 +123,12 @@ async def _wrapper(fcn, scheduler, state, timings=False):
start_time = time()
try:
await fcn(scheduler, state)
except CylcError as exc:
# allow CylcErrors through (e.g. SchedulerStop)
# NOTE: the `from None` bit gets rid of this gunk:
# > During handling of the above exception another exception
raise MainLoopPluginException(exc) from None
except Exception as exc:
if isinstance(exc, CylcError):
# allow CylcErrors through (e.g. SchedulerStop)
raise
LOG.error(f'Error in main loop plugin {sig}')
LOG.exception(exc)
else:
Expand Down
7 changes: 5 additions & 2 deletions cylc/flow/main_loop/health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ async def during(scheduler, _):

def _check_suite_run_dir(scheduler):
if not os.path.exists(scheduler.suite_run_dir):
raise CylcError('Suite run directory cannot be accessed.')
raise CylcError(
'Suite run directory does not exist:'
f' {scheduler.suite_run_dir}'
)


def _check_contact_file(scheduler):
try:
contact_data = suite_files.load_contact_file(
scheduler.suite)
if contact_data != scheduler.contact_data:
raise AssertionError('contact file modified')
raise CylcError('contact file modified')
except (AssertionError, IOError, ValueError, SuiteServiceFileError):
raise CylcError(
'%s: contact file corrupted/modified and may be left'
Expand Down
5 changes: 3 additions & 2 deletions cylc/flow/tests/main_loop/main_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from cylc.flow import CYLC_LOG
from cylc.flow.exceptions import CylcError
from cylc.flow.main_loop import (
load_plugins,
MainLoopPluginException,
_wrapper,
load_plugins,
before,
during,
after
Expand Down Expand Up @@ -132,7 +133,7 @@ async def test_coro(*_):
None,
None
)
with pytest.raises(CylcError):
with pytest.raises(MainLoopPluginException):
asyncio.run(coro)


Expand Down
2 changes: 1 addition & 1 deletion tests/events/48-suite-aborted.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ suite_run_fail "${TEST_NAME_BASE}-run" \
cylc cat-log "${SUITE_NAME}" >'log'
grep_ok 'CRITICAL - Suite shutting down - contact file modified' 'log'
cmp_ok "${SUITE_RUN_DIR}/handler.out" <<'__OUT__'
contact file modified
aborted contact file modified
__OUT__

purge_suite "${SUITE_NAME}"
Expand Down

0 comments on commit d9f1106

Please sign in to comment.