diff --git a/reframe/core/exceptions.py b/reframe/core/exceptions.py index 16905345bd..f254d68328 100644 --- a/reframe/core/exceptions.py +++ b/reframe/core/exceptions.py @@ -7,6 +7,7 @@ # Base regression exceptions # +import contextlib import inspect import os import sys @@ -156,12 +157,23 @@ class ContainerError(ReframeError): class BuildError(ReframeError): '''Raised when a build fails.''' - def __init__(self, stdout, stderr): + def __init__(self, stdout, stderr, prefix=None): super().__init__() - self._message = ( - "standard error can be found in `%s', " - "standard output can be found in `%s'" % (stderr, stdout) - ) + num_lines = 10 + prefix = prefix or '.' + lines = [ + f'stdout: {stdout!r}, stderr: {stderr!r}', + f'--- {stderr} (first {num_lines} lines) ---' + ] + with contextlib.suppress(OSError): + with open(os.path.join(prefix, stderr)) as fp: + for i, line in enumerate(fp): + if i < num_lines: + # Remove trailing '\n' + lines.append(line[:-1]) + + lines += [f'--- {stderr} --- '] + self._message = '\n'.join(lines) class SpawnedProcessError(ReframeError): diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 881a7609fb..9e87c01557 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -1294,7 +1294,8 @@ def compile_wait(self): # We raise a BuildError when we an exit code and it is non zero if self._build_job.exitcode: - raise BuildError(self._build_job.stdout, self._build_job.stderr) + raise BuildError(self._build_job.stdout, + self._build_job.stderr, self._stagedir) self.build_system.post_build(self._build_job)