Proper way to abort after failed validation

What is the proper way to detect that validation has failed and that extraction and integration should not continue?

We want to run the different stages explicitly and have:

    # .. create and collect using manually created pyblish_context
    pyblish.util.validate(pyblish_context)
    pyblish.util.extract(pyblish_context)
    pyblish.util.integrate(pyblish_context)

If validation fails, what is the recommended way of detecting this? Should we go through results on the pyblish_context and look for errors and then simply not run extract/integrate?

Hi @mattiaslagergren!

Should we go through results on the pyblish_context and look for errors and then simply not run extract/integrate?

That’s right, for every plug-in and every instance a result dictionary is produced and stored in the Context. You could inspect this and determine whether or not to continue publishing.

from pyblish import api, util

# Initial setup
class BrokenValidator(api.ContextPlugin):
    order = api.ValidatorOrder

    def process(self, context):
        assert False, "I'm broken. :("

api.register_plugin(BrokenValidator)

# Publish
context = api.Context()

util.collect(context)
util.validate(context)

if any(not result["success"] for result in context.data["results"]):
    print("Validation failed, and here's why..")
    # See learn.pyblish.com for help with formatting an error report.

else:
    util.extract(context)
    util.integrate(context)

Here are some tutorials on formatting error reports from http://learn.pyblish.com.

Let me know if it works for you.

Pro tip: If you tag a thread “support”, then I’ll get a notification and might be able to reply quicker.

Thanks you for the answer Marcus, and thanks for the pro tip