Skip to content

Commit c253dcf

Browse files
author
Vasileios Karakasis
authored
Merge pull request #1873 from teojgo/feat/preview_build_error
[feat] Show a preview of the standard error in cases of build failures
2 parents 4645df4 + b817a02 commit c253dcf

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

reframe/core/exceptions.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Base regression exceptions
88
#
99

10+
import contextlib
1011
import inspect
1112
import os
1213
import sys
@@ -156,12 +157,23 @@ class ContainerError(ReframeError):
156157
class BuildError(ReframeError):
157158
'''Raised when a build fails.'''
158159

159-
def __init__(self, stdout, stderr):
160+
def __init__(self, stdout, stderr, prefix=None):
160161
super().__init__()
161-
self._message = (
162-
"standard error can be found in `%s', "
163-
"standard output can be found in `%s'" % (stderr, stdout)
164-
)
162+
num_lines = 10
163+
prefix = prefix or '.'
164+
lines = [
165+
f'stdout: {stdout!r}, stderr: {stderr!r}',
166+
f'--- {stderr} (first {num_lines} lines) ---'
167+
]
168+
with contextlib.suppress(OSError):
169+
with open(os.path.join(prefix, stderr)) as fp:
170+
for i, line in enumerate(fp):
171+
if i < num_lines:
172+
# Remove trailing '\n'
173+
lines.append(line[:-1])
174+
175+
lines += [f'--- {stderr} --- ']
176+
self._message = '\n'.join(lines)
165177

166178

167179
class SpawnedProcessError(ReframeError):

reframe/core/pipeline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ def compile_wait(self):
12941294

12951295
# We raise a BuildError when we an exit code and it is non zero
12961296
if self._build_job.exitcode:
1297-
raise BuildError(self._build_job.stdout, self._build_job.stderr)
1297+
raise BuildError(self._build_job.stdout,
1298+
self._build_job.stderr, self._stagedir)
12981299

12991300
self.build_system.post_build(self._build_job)
13001301

0 commit comments

Comments
 (0)