diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 9a465ea2af..5443675505 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -737,16 +737,22 @@ def restrict_logging(): # Update options from the selected execution mode if options.mode: - mode_args = site_config.get(f'modes/@{options.mode}/options') - - # We lexically split the mode options, because otherwise spaces - # will be treated as part of the option argument; see GH bug #1554 - mode_args = list(itertools.chain.from_iterable(shlex.split(m) - for m in mode_args)) - # Parse the mode's options and reparse the command-line - options = argparser.parse_args(mode_args) - options = argparser.parse_args(namespace=options.cmd_options) - options.update_config(site_config) + mode = site_config.get(f'modes/@{options.mode}') + if mode is None: + printer.warning(f'invalid mode: {options.mode!r}; ignoring...') + else: + mode_args = site_config.get(f'modes/@{options.mode}/options') + + # We lexically split the mode options, because otherwise spaces + # will be treated as part of the option argument; + # see GH bug #1554 + mode_args = list( + itertools.chain.from_iterable(shlex.split(m) + for m in mode_args)) + # Parse the mode's options and reparse the command-line + options = argparser.parse_args(mode_args) + options = argparser.parse_args(namespace=options.cmd_options) + options.update_config(site_config) logging.configure_logging(site_config) except (OSError, errors.ConfigError) as e: diff --git a/unittests/test_cli.py b/unittests/test_cli.py index bfdb59f366..adfe5d0fe3 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -478,6 +478,20 @@ def test_execution_modes(run_reframe): assert 'Ran 2/2 test case' in stdout +def test_invalid_mode_warning(run_reframe): + mode = 'invalid' + returncode, stdout, stderr = run_reframe( + action='list', + checkpath=[], + environs=[], + local=False, + mode=mode + ) + assert 'Traceback' not in stdout + assert 'Traceback' not in stderr + assert f'invalid mode: {mode!r}; ignoring' in stdout + + def test_timestamp_option(run_reframe): timefmt = time.strftime('xxx_%F') returncode, stdout, _ = run_reframe(