Skip to content

Commit eee81c8

Browse files
author
Vasileios Karakasis
committed
Fix crash when init_modules_system throws
- Catch errors raised by `init_modules_system` in the CLI and report nicely to user
1 parent f0f81f2 commit eee81c8

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

reframe/core/modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def init_modules_system(modules_kind=None):
513513
elif modules_kind == 'lmod':
514514
_modules_system = ModulesSystem(LModImpl())
515515
else:
516-
raise ConfigError('unknown module system')
516+
raise ConfigError('unknown module system: %s' % modules_kind)
517517

518518

519519
def get_modules_system():

reframe/frontend/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,12 @@ def main():
226226
list_supported_systems(site_config.systems.values(), printer)
227227
sys.exit(1)
228228

229-
# Init modules system
230-
init_modules_system(system.modules_system)
229+
try:
230+
# Init modules system
231+
init_modules_system(system.modules_system)
232+
except ReframeError as e:
233+
printer.error('could not initialize the modules system: %s' % e)
234+
sys.exit(1)
231235

232236
if options.mode:
233237
try:

unittests/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import itertools
23
import os
34
import re
@@ -293,5 +294,16 @@ def test_execution_modes(self):
293294
self.assertIn('PASSED', stdout)
294295
self.assertIn('Ran 1 test case', stdout)
295296

297+
def test_unknown_modules_system(self):
298+
# Monkey patch site configuration to trigger a module systems error
299+
site_config_save = copy.deepcopy(settings._site_configuration)
300+
systems = list(settings._site_configuration['systems'].keys())
301+
for s in systems:
302+
settings._site_configuration['systems'][s]['modules_system'] = 'foo'
303+
304+
returncode, stdout, stderr = self._run_reframe()
305+
self.assertNotEqual(0, returncode)
306+
settings._site_configuration = site_config_save
307+
296308
def tearDown(self):
297309
shutil.rmtree(self.prefix)

0 commit comments

Comments
 (0)