-
Notifications
You must be signed in to change notification settings - Fork 203
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de09a35
fix origin of raised EasyBuildError in logged error message
boegel 2ae446e
update comment
boegel 3b26b1e
fleshed out code to determine location info in EasyBuildError to Logg…
boegel b39c586
remove unused import
boegel f5e7423
bump required vsc-base version
boegel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)