Skip to content

Commit 7188468

Browse files
authored
Merge pull request #4065 from Flamefire/error-parse
Print potential errors after running a command only once
2 parents fcab3eb + 68d274c commit 7188468

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

easybuild/tools/run.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -623,19 +623,19 @@ def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp):
623623
"""
624624
if strictness == IGNORE:
625625
check_ec = False
626-
use_regexp = False
626+
fail_on_error_match = False
627627
elif strictness == WARN:
628628
check_ec = True
629-
use_regexp = False
629+
fail_on_error_match = False
630630
elif strictness == ERROR:
631631
check_ec = True
632-
use_regexp = True
632+
fail_on_error_match = True
633633
else:
634634
raise EasyBuildError("invalid strictness setting: %s", strictness)
635635

636636
# allow for overriding the regexp setting
637637
if not regexp:
638-
use_regexp = False
638+
fail_on_error_match = False
639639

640640
if ec and (log_all or log_ok):
641641
# We don't want to error if the user doesn't care
@@ -650,14 +650,16 @@ def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp):
650650
_log.debug('cmd "%s" exited with exit code %s and output:\n%s' % (cmd, ec, stdouterr))
651651

652652
# parse the stdout/stderr for errors when strictness dictates this or when regexp is passed in
653-
if use_regexp or regexp:
654-
res = parse_log_for_error(stdouterr, regexp, msg="Command used: %s" % cmd)
655-
if len(res) > 0:
656-
message = "Found %s errors in command output (output: %s)" % (len(res), "\n\t".join([r[0] for r in res]))
657-
if use_regexp:
658-
raise EasyBuildError(message)
653+
if fail_on_error_match or regexp:
654+
res = parse_log_for_error(stdouterr, regexp, stdout=False)
655+
if res:
656+
errors = "\n\t" + "\n\t".join([r[0] for r in res])
657+
error_str = "error" if len(res) == 1 else "errors"
658+
if fail_on_error_match:
659+
raise EasyBuildError("Found %s %s in output of %s:%s", len(res), error_str, cmd, errors)
659660
else:
660-
_log.warning(message)
661+
_log.warning("Found %s potential %s (some may be harmless) in output of %s:%s",
662+
len(res), error_str, cmd, errors)
661663

662664
if simple:
663665
if ec:

0 commit comments

Comments
 (0)