Decorating runAction functions in component Script actions?

Is it possible to decorate these runAction functions? I want to show any errors in the script to the user and maybe do other actions, but at the moment I just copy boiler plate code with try/except blocks, however I'd really like to globally define this in a script module as a decorator function to do what I want so that I can centrally manage it and modify it if I need.

Is this at all possible?

Most of the time I have the scripts I call defined within script modules, however if there's a typo or something preventing that function call from running, these will go silently by without the user knowing anything happened or that there was an error.

E.g.

@shared.decorators.runActions
def runAction(self, event):
   sharred.prespective.sayHello() # typos in the module name prevents code from running, but won't be flagged without error handling
2 Likes

No. You should be using one-liners calling to the project library, and you can decorate those.

1 Like

I mean, technically this would be possible under the hood, as far as I know. Would require some significant changes to the editor logic and the way these scripts are stored under the hood, which on its own makes it unpalatable, but not totally inconceivable.

In your example, though, you're just as likely to typo shared.deccorators.runActions as you are sharred.perspective.sayHello :person_shrugging:, so even above the implementation-wise reasons not to do it I'm not convinced by this example.

If you don't want the full 'ceremony' of a project library script, you could also write the business logic as a custom method, and decorate that from runAction;

def runAction(self, event)
    @shared.decorators.runActions
    self.sayHello()
1 Like