From de09a3522b4e2bcbc9f0a8410ac8626602a809e9 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Tue, 31 Mar 2015 21:09:13 +0200 Subject: [PATCH 1/5] fix origin of raised EasyBuildError in logged error message --- easybuild/tools/build_log.py | 17 +++++++++++++++-- test/framework/build_log.py | 2 +- test/framework/options.py | 7 ++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/easybuild/tools/build_log.py b/easybuild/tools/build_log.py index b64b5f648e..aeb0b26bc6 100644 --- a/easybuild/tools/build_log.py +++ b/easybuild/tools/build_log.py @@ -31,6 +31,7 @@ @author: Pieter De Baets (Ghent University) @author: Jens Timmerman (Ghent University) """ +import inspect import os import sys import tempfile @@ -63,7 +64,19 @@ class EasyBuildError(LoggedException): def __init__(self, msg, *args): """Constructor: initialise EasyBuildError instance.""" - msg = msg % args + # figure out where error was raised from + # current frame: this constructor, one frame above: location where this EasyBuildError was created/raised + frameinfo = inspect.getouterframes(inspect.currentframe())[1] + + # determine short location of Python module where error was raised from (starting with 'easybuild/') + path_parts = frameinfo[1].split(os.path.sep) + relpath = path_parts.pop() + while not (relpath.startswith('easybuild/') or relpath.startswith('vsc/')) and path_parts: + relpath = os.path.join(path_parts.pop() or os.path.sep, relpath) + + # include location info at the end of the message + # for example: "Nope, giving up (at easybuild/tools/somemodule.py:123 in some_function)" + msg = "%s (at %s:%s in %s)" % (msg % args, relpath, frameinfo[2], frameinfo[3]) LoggedException.__init__(self, msg) self.msg = msg @@ -133,7 +146,7 @@ def _error_no_raise(self, msg): orig_raise_error = self.raiseError self.raiseError = False - self.error(msg) + fancylogger.FancyLogger.error(self, msg) # reinstate previous raiseError setting self.raiseError = orig_raise_error diff --git a/test/framework/build_log.py b/test/framework/build_log.py index cd97e53b32..e4773e83e6 100644 --- a/test/framework/build_log.py +++ b/test/framework/build_log.py @@ -65,7 +65,7 @@ def test_easybuilderror(self): self.assertErrorRegex(EasyBuildError, 'BOOM', raise_easybuilderror, 'BOOM') logToFile(tmplog, enable=False) - log_re = re.compile("^%s :: EasyBuild crashed .*: BOOM$" % getRootLoggerName(), re.M) + log_re = re.compile("^%s :: BOOM \(at %s:[0-9]+ in [a-z_]+\)$" % (getRootLoggerName(), __file__), re.M) logtxt = open(tmplog, 'r').read() self.assertTrue(log_re.match(logtxt), "%s matches %s" % (log_re.pattern, logtxt)) diff --git a/test/framework/options.py b/test/framework/options.py index 0f381055a0..038844dac1 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -109,7 +109,7 @@ def test_no_args(self): outtxt = self.eb_main([]) - error_msg = "ERROR .* Please provide one or multiple easyconfig files," + error_msg = "ERROR Please provide one or multiple easyconfig files," error_msg += " or use software build options to make EasyBuild search for easyconfigs" self.assertTrue(re.search(error_msg, outtxt), "Error message when eb is run without arguments") @@ -922,9 +922,10 @@ def test_no_such_software(self): outtxt = self.eb_main(args) # error message when template is not found - error_msg1 = "ERROR .* No easyconfig files found for software nosuchsoftware, and no templates available. I'm all out of ideas." + error_msg1 = "ERROR No easyconfig files found for software nosuchsoftware, and no templates available. " + error_msg1 += "I'm all out of ideas." # error message when template is found - error_msg2 = "ERROR .* Unable to find an easyconfig for the given specifications" + error_msg2 = "ERROR Unable to find an easyconfig for the given specifications" msg = "Error message when eb can't find software with specified name (outtxt: %s)" % outtxt self.assertTrue(re.search(error_msg1, outtxt) or re.search(error_msg2, outtxt), msg) From 2ae446e5ff8f4bc1fb004183b59738b96f109870 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Tue, 31 Mar 2015 21:16:32 +0200 Subject: [PATCH 2/5] update comment --- easybuild/tools/build_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easybuild/tools/build_log.py b/easybuild/tools/build_log.py index aeb0b26bc6..f6a30e850e 100644 --- a/easybuild/tools/build_log.py +++ b/easybuild/tools/build_log.py @@ -68,7 +68,7 @@ def __init__(self, msg, *args): # current frame: this constructor, one frame above: location where this EasyBuildError was created/raised frameinfo = inspect.getouterframes(inspect.currentframe())[1] - # determine short location of Python module where error was raised from (starting with 'easybuild/') + # determine short location of Python module where error was raised from (starting with 'easybuild/' or 'vsc/') path_parts = frameinfo[1].split(os.path.sep) relpath = path_parts.pop() while not (relpath.startswith('easybuild/') or relpath.startswith('vsc/')) and path_parts: From 3b26b1e2869f85d99df933fa7537f7e64a8e6a52 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Sun, 5 Apr 2015 23:08:30 +0200 Subject: [PATCH 3/5] fleshed out code to determine location info in EasyBuildError to LoggedException in vsc-base --- easybuild/tools/build_log.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/easybuild/tools/build_log.py b/easybuild/tools/build_log.py index f6a30e850e..b336495252 100644 --- a/easybuild/tools/build_log.py +++ b/easybuild/tools/build_log.py @@ -58,25 +58,17 @@ class EasyBuildError(LoggedException): """ EasyBuildError is thrown when EasyBuild runs into something horribly wrong. """ + LOC_INFO_TOP_PKG_NAMES = ['easybuild', 'vsc'] + LOC_INFO_LEVEL = 1 + # use custom error logging method, to make sure EasyBuildError isn't being raised again to avoid infinite recursion # only required because 'error' log method raises (should no longer be needed in EB v3.x) LOGGING_METHOD_NAME = '_error_no_raise' def __init__(self, msg, *args): """Constructor: initialise EasyBuildError instance.""" - # figure out where error was raised from - # current frame: this constructor, one frame above: location where this EasyBuildError was created/raised - frameinfo = inspect.getouterframes(inspect.currentframe())[1] - - # determine short location of Python module where error was raised from (starting with 'easybuild/' or 'vsc/') - path_parts = frameinfo[1].split(os.path.sep) - relpath = path_parts.pop() - while not (relpath.startswith('easybuild/') or relpath.startswith('vsc/')) and path_parts: - relpath = os.path.join(path_parts.pop() or os.path.sep, relpath) - - # include location info at the end of the message - # for example: "Nope, giving up (at easybuild/tools/somemodule.py:123 in some_function)" - msg = "%s (at %s:%s in %s)" % (msg % args, relpath, frameinfo[2], frameinfo[3]) + if args: + msg = msg % args LoggedException.__init__(self, msg) self.msg = msg From b39c586cd26f569a70658fb7b128e402f42870ae Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Sun, 5 Apr 2015 23:11:09 +0200 Subject: [PATCH 4/5] remove unused import --- easybuild/tools/build_log.py | 1 - 1 file changed, 1 deletion(-) diff --git a/easybuild/tools/build_log.py b/easybuild/tools/build_log.py index b336495252..b663dbe30e 100644 --- a/easybuild/tools/build_log.py +++ b/easybuild/tools/build_log.py @@ -31,7 +31,6 @@ @author: Pieter De Baets (Ghent University) @author: Jens Timmerman (Ghent University) """ -import inspect import os import sys import tempfile From f5e742300cb92928f74706139d3644070bd0a9ab Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Sun, 5 Apr 2015 23:14:23 +0200 Subject: [PATCH 5/5] bump required vsc-base version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4fecf38036..6335ba4f77 100644 --- a/setup.py +++ b/setup.py @@ -106,5 +106,5 @@ def find_rel_test(): provides=["eb"] + easybuild_packages, test_suite="test.framework.suite", zip_safe=False, - install_requires=["vsc-base >= 2.1.1"], + install_requires=["vsc-base >= 2.2.0"], )