Blender Python: Call operator function from another function? It looks like the best way to report a user-error to the user is by using self.report() of Operator types. However, what about when the operator calls a global function that needs to report a specific error? Is there any way to reach back to the calling operator and have it throw an error with a specific message?
The classic method to handle something like this would be to have the global function return some type of error index, then have the operator send a string that relates to the error type. But this creates a lot of relationship links between the operator and the functions it calls. If I later change the function, I have to also modify the operator.
Is there a simple way to pull this off? Either to access the &quot;active&quot; operator or to throw a global user error?
You can pass what you want and even self, this way it is easy determine where the call is coming from. Operator based on Templates > Python > Operator Simple:

import bpy


def main(operator, context):
    print (operator, context)
    operator.report({'INFO'}, 'Call is comming from: {}'.format(operator))
    #return operator


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        main(self, context)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator()