Is there a way to make connect error out if an argument is incorrect?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By oskfo

For example, I had the following line:

    state_node.connect("finished", self, "_change_state")

It was supposed to be:

    state_node.connect("finished", self, "change_state")

I got no warnings or errors and it took me a while to realise that _change_state() didn’t exist.

Is there a way to turn on a strict mode or something?

Another example: trying to play an animation that doesn’t exist won’t result in any warnings.

oskfo | 2019-04-12 21:28

:bust_in_silhouette: Reply From: Calinou

The Object.connect() method returns an Error value which you can compare using the Error constants (OK for success, ERR_* for failure). Therefore, if you wish to perform error checking, you need to store the result in a variable, or compare the result of the operation directly as follows:

if state_node.connect("finished", self, "_change_state") != OK:
    push_error("Error connecting state node.")

Well I guess it’s better than nothing, but it makes the code so unnecessarily verbose considering that anyone who wanted to do it that way could just use is_connected()…
Did you see my comment about playing animations, by the way?

oskfo | 2019-04-12 21:48