diff --git a/reframe/core/exceptions.py b/reframe/core/exceptions.py index b59f417042..2e2ccbbd6c 100644 --- a/reframe/core/exceptions.py +++ b/reframe/core/exceptions.py @@ -122,7 +122,7 @@ def __init__(self, command, stdout, stderr, exitcode): self._exitcode = exitcode def __str__(self): - lines = ["Command '{0}' failed with exit code {1}:".format( + lines = ["command '{0}' failed with exit code {1}:".format( self._command, self._exitcode)] lines.append('=== STDOUT ===') if self._stdout: @@ -162,7 +162,7 @@ def __init__(self, command, stdout, stderr, timeout): self.args = command, stdout, stderr, timeout def __str__(self): - lines = ["Command '{0}' timed out after {1}s:".format(self._command, + lines = ["command '{0}' timed out after {1}s:".format(self._command, self._timeout)] lines.append('=== STDOUT ===') if self._stdout: diff --git a/reframe/core/modules.py b/reframe/core/modules.py index d90dcf7c4b..1fb206a95b 100644 --- a/reframe/core/modules.py +++ b/reframe/core/modules.py @@ -410,25 +410,27 @@ def name(self): def version(self): return self._version - def _run_module_command(self, *args): - command = [self._command, *args] - return os_ext.run_command(' '.join(command)) + def _run_module_command(self, *args, msg=None): + command = ' '.join([self._command, *args]) + try: + completed = os_ext.run_command(command, check=True) + except SpawnedProcessError as e: + raise EnvironError(msg) from e + + if self._module_command_failed(completed): + err = SpawnedProcessError(command, + completed.stdout, + completed.stderr, + completed.returncode) + raise EnvironError(msg) from err + + return completed def _module_command_failed(self, completed): return re.search(r'ERROR', completed.stderr) is not None def _exec_module_command(self, *args, msg=None): - completed = self._run_module_command(*args) - if self._module_command_failed(completed): - if msg is None: - msg = 'modules system command failed: ' - if isinstance(completed.args, str): - msg += completed.args - else: - msg += ' '.join(completed.args) - - raise EnvironError(msg) - + completed = self._run_module_command(*args, msg=msg) exec(completed.stdout) def loaded_modules(self): @@ -441,7 +443,8 @@ def loaded_modules(self): def conflicted_modules(self, module): conflict_list = [] - completed = self._run_module_command('show', str(module)) + completed = self._run_module_command( + 'show', str(module), msg="could not show module '%s'" % module) return [Module(m.group(1)) for m in re.finditer(r'^conflict\s+(\S+)', completed.stderr, re.MULTILINE)] @@ -450,12 +453,14 @@ def is_module_loaded(self, module): return module in self.loaded_modules() def load_module(self, module): - self._exec_module_command('load', str(module), - msg='could not load module %s' % module) + self._exec_module_command( + 'load', str(module), + msg="could not load module '%s' correctly" % module) def unload_module(self, module): - self._exec_module_command('unload', str(module), - msg='could not unload module %s' % module) + self._exec_module_command( + 'unload', str(module), + msg="could not unload module '%s' correctly" % module) def unload_all(self): self._exec_module_command('purge') @@ -558,7 +563,8 @@ def _module_command_failed(self, completed): def conflicted_modules(self, module): conflict_list = [] - completed = self._run_module_command('show', str(module)) + completed = self._run_module_command( + 'show', str(module), msg="could not show module '%s'" % module) # Lmod accepts both Lua and and Tcl syntax # The following test allows incorrect syntax, e.g., `conflict diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 3dfe1081d7..2d56c2d619 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -447,8 +447,11 @@ def filter_system(c): for m in options.user_modules: try: rt.modules_system.load_module(m, force=True) - except EnvironError: - printer.info("could not load module `%s': Skipping..." % m) + raise EnvironError("test") + except EnvironError as e: + printer.warning("could not load module '%s' correctly: " + "Skipping..." % m) + printer.debug(str(e)) success = True if options.list: diff --git a/reframe/frontend/printer.py b/reframe/frontend/printer.py index 407d240616..0c2bed3689 100644 --- a/reframe/frontend/printer.py +++ b/reframe/frontend/printer.py @@ -110,6 +110,9 @@ def timestamp(self, msg='', separator=None): def info(self, msg=''): self._logger.info(msg) + def debug(self, msg=''): + self._logger.debug(msg) + def warning(self, msg): msg = AnsiColorizer.colorize('%s: %s' % (sys.argv[0], msg), AnsiColorizer.yellow) diff --git a/unittests/test_exceptions.py b/unittests/test_exceptions.py index 58310cb3cd..7a7e34cd02 100644 --- a/unittests/test_exceptions.py +++ b/unittests/test_exceptions.py @@ -50,7 +50,7 @@ def test_spawned_process_error(self): exc_args = ('foo bar', 'partial output', 'error message', 1) e = exc.SpawnedProcessError(*exc_args) self.assertRaisesRegex(exc.ReframeError, - r"Command 'foo bar' failed with exit code 1:\n" + r"command 'foo bar' failed with exit code 1:\n" r"=== STDOUT ===\n" r'partial output\n' r"=== STDERR ===\n" @@ -62,7 +62,7 @@ def test_spawned_process_error_nostdout(self): exc_args = ('foo bar', '', 'error message', 1) e = exc.SpawnedProcessError(*exc_args) self.assertRaisesRegex(exc.ReframeError, - r"Command 'foo bar' failed with exit code 1:\n" + r"command 'foo bar' failed with exit code 1:\n" r"=== STDOUT ===\n" r"=== STDERR ===\n" r"error message", @@ -72,7 +72,7 @@ def test_spawned_process_error_nostderr(self): exc_args = ('foo bar', 'partial output', '', 1) e = exc.SpawnedProcessError(*exc_args) self.assertRaisesRegex(exc.ReframeError, - r"Command 'foo bar' failed with exit code 1:\n" + r"command 'foo bar' failed with exit code 1:\n" r"=== STDOUT ===\n" r'partial output\n' r"=== STDERR ===", @@ -82,7 +82,7 @@ def test_spawned_process_timeout(self): exc_args = ('foo bar', 'partial output', 'partial error', 10) e = exc.SpawnedProcessTimeout(*exc_args) self.assertRaisesRegex(exc.ReframeError, - r"Command 'foo bar' timed out after 10s:\n" + r"command 'foo bar' timed out after 10s:\n" r"=== STDOUT ===\n" r'partial output\n' r"=== STDERR ===\n" @@ -94,7 +94,7 @@ def test_spawned_process_timeout_nostdout(self): exc_args = ('foo bar', '', 'partial error', 10) e = exc.SpawnedProcessTimeout(*exc_args) self.assertRaisesRegex(exc.ReframeError, - r"Command 'foo bar' timed out after 10s:\n" + r"command 'foo bar' timed out after 10s:\n" r"=== STDOUT ===\n" r"=== STDERR ===\n" r"partial error", @@ -104,7 +104,7 @@ def test_spawned_process_timeout_nostderr(self): exc_args = ('foo bar', 'partial output', '', 10) e = exc.SpawnedProcessTimeout(*exc_args) self.assertRaisesRegex(exc.ReframeError, - r"Command 'foo bar' timed out after 10s:\n" + r"command 'foo bar' timed out after 10s:\n" r"=== STDOUT ===\n" r'partial output\n' r"=== STDERR ===",