Hi Not sure whether I’ve been missing somthing, but if the code I’m writing into pyblish (let say an integration) raise an exception, this never gets reported, and silently go ahead.
Is there any way to make so , it at least report it as error with stacktrace ?
It would be helpful on debugging issues.
Of course, if there’s something already , sorry, and let me know !
Cheers.
L.
All exceptions from plug-ins are treated as errors, put into a result (as the error key) and optionally reported back to the currently running GUI.
from pyblish import api, util
class MyCollector(api.ContextPlugin):
order = api.CollectorOrder
def process(self, context):
context.create_instance("MyInstance")
class MyIntegrator(api.InstancePlugin):
order = api.IntegratorOrder
def process(self, instance):
raise Exception("An error")
api.register_plugin(MyCollector)
api.register_plugin(MyIntegrator)
context = util.publish()
for result in context.data["results"]:
print("'{plugin.__name__}' was run.".format(**result))
if result["error"]:
print("'{instance}' had an error that said '{error}' from '{plugin.__name__}'".format(**result))
print(" The traceback was:\n {error.traceback}".format(**result))
Have a look at the series on reporting with results from the Lean By Example guide for more tips and tricks.
In the GUI, you’ll find them in the Terminal (for both Lite and QML) or the Perspective (for QML).
Thanks Marcus,
but wouldn’t be a bit more handy to catch exceptions and report thorugh a log.error with stacktrace ?
I understand having the results, which is handy for things I know I want to report, but if there’s a bug a typo or an exception in the code, I would like to see it while it happens.
Yeah, this was a primary design goal for the result dictionary. It contains all of this information. pyblish-qml for example does stronger visualisation of the traceback than pyblish-lite through the Terminal and Perspective.
All of that information is provided by the same result dictionary; you could parse this yourself for bespoke use.
# Continuing on from above example
from pyblish_qml.rpc.formatting import format_error
context = util.publish()
error = context.data["results"][4]["error"]
dictionary_of_information = format_error(error)
well for me point is, having pyblish catching all the exceptions, become quite hard to see what’s going on.
so having the ability to see (thus the logging.error) what’s going wrong and keep going would help.
One option could be to have a way to not report as log.error and have it only on the report (ENV driven) ?
Yes, the GUI (pyblish-qml, mostly) is designed to give you this level of verbosity. But if nothing else, you could design such a verbose helper function for yourself.
Success Plug-in -> Instance
----------------------------------------------------------------------
1 CollectCaptainAmerica -> None
0 ValidateCaptainAmerica -> Captain America
+-- EXCEPTION: Captain America must be a hero
verbose=True, seems a good option, as long as it report as actual erros with stack trace,so is asier.
For the PR, I’ll see as soon as I have time.
Cheers.
L.