Skip to content

Commit

Permalink
Merge pull request #4361 from Flamefire/improve-error-check
Browse files Browse the repository at this point in the history
deduplicate warnings & errors found in logs and add initial newline + tab in output
  • Loading branch information
boegel authored Nov 8, 2023
2 parents 685467c + 96c7a04 commit 731649d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from easybuild.tools.config import ERROR, IGNORE, WARN, build_option
from easybuild.tools.hooks import RUN_SHELL_CMD, load_hooks, run_hook
from easybuild.tools.py2vs3 import string_type
from easybuild.tools.utilities import trace_msg
from easybuild.tools.utilities import nub, trace_msg


_log = fancylogger.getLogger('run', fname=False)
Expand Down Expand Up @@ -790,7 +790,7 @@ def extract_errors_from_log(log_txt, reg_exps):
elif action == WARN:
warnings.append(line)
break
return warnings, errors
return nub(warnings), nub(errors)


def check_log_for_errors(log_txt, reg_exps):
Expand All @@ -805,8 +805,8 @@ def check_log_for_errors(log_txt, reg_exps):

errors_found_in_log += len(warnings) + len(errors)
if warnings:
_log.warning("Found %s potential error(s) in command output (output: %s)",
_log.warning("Found %s potential error(s) in command output:\n\t%s",
len(warnings), "\n\t".join(warnings))
if errors:
raise EasyBuildError("Found %s error(s) in command output (output: %s)",
raise EasyBuildError("Found %s error(s) in command output:\n\t%s",
len(errors), "\n\t".join(errors))
16 changes: 10 additions & 6 deletions test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,9 @@ def test_check_log_for_errors(self):
"enabling -Werror",
"the process crashed with 0"
])
expected_msg = r"Found 2 error\(s\) in command output "\
r"\(output: error found\n\tthe process crashed with 0\)"
expected_msg = r"Found 2 error\(s\) in command output:\n"\
r"\terror found\n"\
r"\tthe process crashed with 0"

# String promoted to list
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
Expand All @@ -718,14 +719,17 @@ def test_check_log_for_errors(self):
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
[(r"\b(error|crashed)\b", ERROR)])

expected_msg = "Found 2 potential error(s) in command output " \
"(output: error found\n\tthe process crashed with 0)"
expected_msg = "Found 2 potential error(s) in command output:\n"\
"\terror found\n"\
"\tthe process crashed with 0"
init_logging(logfile, silent=True)
check_log_for_errors(input_text, [(r"\b(error|crashed)\b", WARN)])
stop_logging(logfile)
self.assertIn(expected_msg, read_file(logfile))

expected_msg = r"Found 2 error\(s\) in command output \(output: error found\n\ttest failed\)"
expected_msg = r"Found 2 error\(s\) in command output:\n"\
r"\terror found\n"\
r"\ttest failed"
write_file(logfile, '')
init_logging(logfile, silent=True)
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, [
Expand All @@ -735,7 +739,7 @@ def test_check_log_for_errors(self):
"fail"
])
stop_logging(logfile)
expected_msg = "Found 1 potential error(s) in command output (output: the process crashed with 0)"
expected_msg = "Found 1 potential error(s) in command output:\n\tthe process crashed with 0"
self.assertIn(expected_msg, read_file(logfile))

def test_run_cmd_with_hooks(self):
Expand Down

0 comments on commit 731649d

Please sign in to comment.