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():

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):

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.
unittests/test_cli.py::test_invalid_mode_error
unittests/test_cli.py::test_check_success[run] unittests/test_cli.py::test_check_success[dry_run] unittests/test_cli.py::test_check_restore_session_failed unittests/test_cli.py::test_check_restore_session_succeeded_test unittests/test_cli.py::test_check_restore_session_check_search_path unittests/test_cli.py::test_check_success_force_local[run] unittests/test_cli.py::test_check_success_force_local[dry_run] unittests/test_cli.py::test_report_file_with_sessionid[run] unittests/test_cli.py::test_report_file_with_sessionid[dry_run] unittests/test_cli.py::test_report_ends_with_newline[run] unittests/test_cli.py::test_report_ends_with_newline[dry_run] unittests/test_cli.py::test_report_file_symlink_latest[run] unittests/test_cli.py::test_report_file_symlink_latest[dry_run] unittests/test_cli.py::test_check_failure unittests/test_cli.py::test_check_setup_failure unittests/test_cli.py::test_check_kbd_interrupt unittests/test_cli.py::test_check_sanity_failure[run] unittests/test_cli.py::test_check_sanity_failure[dry_run] unittests/test_cli.py::test_dont_restage unittests/test_cli.py::test_checkpath_symlink unittests/test_cli.py::test_performance_check_failure[run] unittests/test_cli.py::test_performance_check_failure[dry_run] unittests/test_cli.py::test_perflogdir_from_env unittests/test_cli.py::test_performance_report[run] unittests/test_cli.py::test_performance_report[dry_run] unittests/test_cli.py::test_skip_system_check_option[run] unittests/test_cli.py::test_skip_system_check_option[dry_run] unittests/test_cli.py::test_skip_prgenv_check_option[run] unittests/test_cli.py::test_skip_prgenv_check_option[dry_run] unittests/test_cli.py::test_sanity_of_checks unittests/test_cli.py::test_unknown_system unittests/test_cli.py::test_sanity_of_optconfig unittests/test_cli.py::test_checkpath_recursion unittests/test_cli.py::test_same_output_stage_dir unittests/test_cli.py::test_execution_modes[run] unittests/test_cli.py::test_execution_modes[dry_run] unittests/test_cli.py::test_timestamp_option unittests/test_cli.py::test_timestamp_option_default unittests/test_cli.py::test_list_empty_prgenvs_check_and_options unittests/test_cli.py::test_list_check_with_empty_prgenvs unittests/test_cli.py::test_list_empty_prgenvs_in_check_and_options unittests/test_cli.py::test_list_with_details unittests/test_cli.py::test_list_concretized unittests/test_cli.py::test_list_tags unittests/test_cli.py::test_list_tests_with_deps unittests/test_cli.py::test_list_tests_with_fixtures unittests/test_cli.py::test_filtering_multiple_criteria_name unittests/test_cli.py::test_filtering_multiple_criteria_hash unittests/test_cli.py::test_filtering_exclude_hash unittests/test_cli.py::test_filtering_cpu_only unittests/test_cli.py::test_filtering_gpu_only unittests/test_cli.py::test_filtering_by_expr unittests/test_cli.py::test_show_config_all unittests/test_cli.py::test_show_config_param unittests/test_cli.py::test_show_config_unknown_param unittests/test_cli.py::test_show_config_null_param unittests/test_cli.py::test_verbosity unittests/test_cli.py::test_verbosity_with_check unittests/test_cli.py::test_quiesce_with_check unittests/test_cli.py::test_failure_stats[run] unittests/test_cli.py::test_failure_stats[dry_run] unittests/test_cli.py::test_maxfail_option unittests/test_cli.py::test_maxfail_invalid_option unittests/test_cli.py::test_maxfail_negative unittests/test_cli.py::test_repeat_option[run] unittests/test_cli.py::test_repeat_option[dry_run] unittests/test_cli.py::test_repeat_invalid_option unittests/test_cli.py::test_repeat_negative unittests/test_cli.py::test_parameterize_tests unittests/test_cli.py::test_parameterize_tests_invalid_params unittests/test_cli.py::test_reruns_negative unittests/test_cli.py::test_reruns_with_duration unittests/test_cli.py::test_exec_order[name] unittests/test_cli.py::test_exec_order[rname] unittests/test_cli.py::test_exec_order[uid] unittests/test_cli.py::test_exec_order[ruid] unittests/test_cli.py::test_exec_order[random] unittests/test_cli.py::test_detect_host_topology unittests/test_cli.py::test_detect_host_topology_file unittests/test_cli.py::test_external_vars[run] unittests/test_cli.py::test_external_vars[dry_run] unittests/test_cli.py::test_external_vars_invalid_expr[run] unittests/test_cli.py::test_external_vars_invalid_expr[dry_run] unittests/test_cli.py::test_fixture_registry_env_sys unittests/test_cli.py::test_fixture_resolution[run] unittests/test_cli.py::test_fixture_resolution[dry_run] unittests/test_cli.py::test_dynamic_tests[run] unittests/test_cli.py::test_dynamic_tests[dry_run] unittests/test_cli.py::test_dynamic_tests_filtering[run] unittests/test_cli.py::test_dynamic_tests_filtering[dry_run] unittests/test_cli.py::test_testlib_inherit_fixture_in_different_files