-
Notifications
You must be signed in to change notification settings - Fork 59
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
Traceback available in error results #356
Traceback available in error results #356
Conversation
Based on this PR/discussion: pyblish#347 (comment)
If plugins are registered through `api.plugin.discover`, they only show "<string>" instead of the actual source file.
Ok, I've had a look at this and unfortunately it reproduces the problem with #347, in that we now have duplicate data. Here's the data present in the test.py from pyblish import api, util
class Plugin(api.ContextPlugin):
def process(self, context):
assert False, "This was a problem"
api.register_plugin(Plugin)
ctx = util.publish()
error = ctx.data["results"][-1]["error"]
fname, lineno, func, msg = error.traceback
print(fname, lineno, func, msg) Python 2 > $ python .\test.py
This was a problem
('.\\test.py', 5, 'process', 'assert False, "This was a problem"') Python 3 > $ python .\test.py
This was a problem
.\test.py 5 process assert False, "This was a problem" Notice how all information in the new In addition, this PR includes support for a We could support that, like you have here, but we would need a usecase for it. A reason. Other than supporting |
Duplicated data Basically this is the only thing we'd need: test.py from pyblish import api, util
class Plugin(api.ContextPlugin):
def process(self, context):
assert False, "This was a problem"
api.register_plugin(Plugin)
ctx = util.publish()
error = ctx.data["results"][-1]["error"]
fname, lineno, func, msg = error.traceback
formatted_traceback = error.formatted_traceback # This would be new
print(fname, lineno, func, msg)
print(formatted_traceback) Result:
String paths from pyblish import api
api.register_plugin_path("my/plugin/path")
api.discover() Which leads to the |
👍 To add a little note from my end. Exactly this is what I'd like to see too: Traceback (most recent call last):
File "/pyblish/plugin.py", line 518, in __explicit_process
runner(*args)
File "/test.py", line 5, in process
AssertionError: This was a problem Especially the full traceback that also includes this information: |
Yes, that looks good to me.
No that's the right way, and I see the problem now. This is a bug. Plug-ins coming from I had a look to see whether there was an easy fix here, but came up short. The problem is how So in addition to your fix for converting lib.extract_traceback(error)
if error.traceback[0] == "<string>":
error.traceback = (os.path.abspath(plugin.__module__),) + error.traceback[1:]
result["error"] = error Idealy, the formatting would then be able to use this path, so we wouldn't have to check for With this, we should have a fully correct error. |
Done
The formatting of the exception message is an internal process of the traceback module and it relies on sys.exc_info and not the extracted data so I don't see a way to inject the correct file path in there. |
pyblish/lib.py
Outdated
@@ -53,10 +53,32 @@ def emit(self, record): | |||
self.records.append(record) | |||
|
|||
|
|||
def extract_traceback(exception): | |||
"""Inject current traceback and store in exception""" | |||
def extract_traceback(exception, plugin): |
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.
Sorry to keep picking on this, but something only become apparent when you're just about to merge. xD
Could we make this function take a fname=None
argument instead? Having it take plugin
implies some dependency on Pyblish's Plugin class, and it's actually quite general and has to do with overriding the fname
found in the exception
argument. That would make it squeaky clean.
If you're done with this, I understand and could take a look at it myself in the coming days.
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.
No worries, I'll add that later today
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.
It's changed
Thanks, great work! |
Awesome stuff @PaulSchweizer ! |
I completely missed this happening. Yeah, this will work for us as well in our pyblish lite. The result should be exactly what we were after in #347. Nice job. |
Based on this PR/discussion: #347 (comment)
I also added logging of the error, useful for situations where there is no UI and/or something unexpected occurs but I'm not sure if there are arguments against this?
As for the unittest, I am not sure if this is the correct location, please let me know where the test should go.