Repository: reframe-hpc/reframe

Issue:
Passing an invalid mode should issue an error not a warning
Currently, passing an inexistent mode with the `--mode` option, only a warning will be issued and the option will be ignored. This is error prone, as reframe continues execution as if the option wasn't passed.

Discussion:

Patch:
diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py
index 8c59a680..2a257c11 100644
--- a/reframe/frontend/cli.py
+++ b/reframe/frontend/cli.py
@@ -791,7 +791,7 @@ def main():
         if options.mode:
             mode = site_config.get(f'modes/@{options.mode}')
             if mode is None:
-                printer.warning(f'invalid mode: {options.mode!r}; ignoring...')
+                raise errors.ReframeError(f'invalid mode: {options.mode!r}')
             else:
                 mode_args = site_config.get(f'modes/@{options.mode}/options')
 
@@ -811,6 +811,10 @@ def main():
         printer.error(f'failed to load configuration: {e}')
         printer.info(logfiles_message())
         sys.exit(1)
+    except errors.ReframeError as e:
+        printer.error(str(e))
+        printer.info(logfiles_message())
+        sys.exit(1)
 
     printer.colorize = site_config.get('general/0/colorize')
     if not restrict_logging():


Test patch:
diff --git a/unittests/test_cli.py b/unittests/test_cli.py
index d5d8f148..b468658f 100644
--- a/unittests/test_cli.py
+++ b/unittests/test_cli.py
@@ -527,7 +527,7 @@ def test_execution_modes(run_reframe, run_action):
     assert 'Ran 1/1 test case' in stdout
 
 
-def test_invalid_mode_warning(run_reframe):
+def test_invalid_mode_error(run_reframe):
     mode = 'invalid'
     returncode, stdout, stderr = run_reframe(
         action='list',
@@ -538,7 +538,8 @@ def test_invalid_mode_warning(run_reframe):
     )
     assert 'Traceback' not in stdout
     assert 'Traceback' not in stderr
-    assert f'invalid mode: {mode!r}; ignoring' in stdout
+    assert returncode == 1
+    assert f'ERROR: invalid mode: {mode!r}' in stdout
 
 
 def test_timestamp_option(run_reframe):