Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix origin of raised EasyBuildError in logged error message #1249

Merged
merged 5 commits into from
Apr 9, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions easybuild/tools/build_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@author: Pieter De Baets (Ghent University)
@author: Jens Timmerman (Ghent University)
"""
import inspect
import os
import sys
import tempfile
Expand Down Expand Up @@ -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]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing remark by @stdweird: this is quite generic, so let's move it to vsc-base instead, and add support to LoggedException to disable this optionally (but have it enabled by default)


# 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% happy with this, but couldn't find a better way after trying for a while.

Code golf: only retain the interesting part from something like /Users/kehoste/work/easybuild-framework/easybuild/tools/filetools.py, i.e. the easybuild/tools/filetools.py part.


# 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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/framework/build_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
7 changes: 4 additions & 3 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand Down