It’s a problem with the MouseTracker element then. I think it happens when you exit the experiment before the trial has reached the line newMouseTracker("mouse"). Try moving this line at the top of the trial (i.e. after newTrial("test_trial",) and of course use getMouseTracker("mouse") instead where the line currently is.
Let me know if this fixes the problem