You marked your question as Godot 3.x but it seems like you are using Godot 4.x based on the syntax. I’m not sure the script you posted is relevant, and the errors in the output are impossible to diagnose without the respective script.
If enemy.direction is how the enemy moves then maybe you need to only set the enemy.direction once rather than per-frame. Such as using that _on_body_exited function?