pyblish / pyblish-base

Pyblish base library - see https://github.com/pyblish/pyblish for details.
Other
127 stars 59 forks source link

Pyblish fails when it tries to process InstancePlugin with typo process argument "instance" #350

Open BigRoy opened 5 years ago

BigRoy commented 5 years ago

Issue

Whenever you implement a pyblish.api.InstancePlugin with a process method that does not have the argument instance but it's written differently/wrong then Pyblish QML will raise the following assertion error:

Traceback (most recent call last):
  ...
  File "D:\pyblish_qml\ipc\server.py", line 280, in _listen
    result = wrapper(func, *args)  # block..
  File "D:\pyblish_qml\host.py", line 41, in _wrapper
    raise e
AssertionError: Cannot process an InstancePlugin without an instance. This is a bug

For example, the following will reproduce this error:

import pyblish.api

class Collector(pyblish.api.InstancePlugin):
    order = pyblish.api.CollectorOrder

    def process(self, wrong):
        pass

Notice how the argument is wrong as opposed to instance.

Similarly context fails on an InstancePlugin too with the same error:

import pyblish.api

class Collector(pyblish.api.InstancePlugin):
    order = pyblish.api.CollectorOrder

    def process(self, context):
        pass

Proposal

It would be great if the error would be resolved into a message describing which plug-in is faulty with some information for the developer on how to potentially resolve it.

Reference:


I've also tried to reproduce the other way around with pyblish.api.ContextPlugin but it doesn't run into the same issue, however does have an issue of its own which should be a separate issue than this, see pyblish/pyblish-qml#339.

BigRoy commented 5 years ago

Transferred this from pyblish-qml to pyblish-base. Here's the stack trace from pyblish-base:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "D:\git_pipeline\avalon\development\git\pyblish-base\pyblish\util.py", line 193, in collect
    for result in collect_iter(context, plugins, targets):
  File "D:\git_pipeline\avalon\development\git\pyblish-base\pyblish\util.py", line 252, in collect_iter
    context, plugins, targets):
  File "D:\git_pipeline\avalon\development\git\pyblish-base\pyblish\util.py", line 300, in _convenience_iter
    for result in publish_iter(context, plugins, targets):
  File "D:\git_pipeline\avalon\development\git\pyblish-base\pyblish\util.py", line 119, in publish_iter
    result = plugin.process(Plugin, context, instance)
  File "D:\git_pipeline\avalon\development\git\pyblish-base\pyblish\plugin.py", line 460, in process
    result = __explicit_process(plugin, context, instance, action)
  File "D:\git_pipeline\avalon\development\git\pyblish-base\pyblish\plugin.py", line 479, in __explicit_process
    raise AssertionError("Cannot process an InstancePlugin without an "
AssertionError: Cannot process an InstancePlugin without an instance. This is a bug

Tested with the above example plug-ins and running the following:

import pyblish.util
pyblish.util.collect()
hannesdelbeke commented 2 years ago

moving your repro steps all in one block of code:

import pyblish.api
import pyblish.util

class Collector(pyblish.api.InstancePlugin):
    order = pyblish.api.CollectorOrder

    def process(self, context):
        pass

pyblish.api.register_plugin(Collector)
pyblish.util.collect()

prints:

# Error: AssertionError: file C:\Projects\pyblish-base\pyblish\plugin.py line 490: Cannot process an InstancePlugin without an instance. This is a bug # 
hannesdelbeke commented 2 years ago

would simply changing

raise AssertionError("Cannot process an InstancePlugin without an ""instance. This is a bug." )

to

raise AssertionError("Cannot process an InstancePlugin without an ""instance. This is a bug. Affected plugin:" + str(plugin))

be enough to resolve this? output for your example now tells you which plugin it fails on. # Error: AssertionError: file C:\Projects\pyblish-base\pyblish\plugin.py line 491: Cannot process an InstancePlugin without an instance. This is a bug. Affected plugin:<class 'pyblish.plugin.Collector'>#