Write JS - syntax error in Line 1 when polygons are present in the experiment

OS: Windows 11 Education 23H2
PsychoPy Version: 2024.2.4

I’m having some issues when converting my experiment to JavaScript for running it online. Each time I try, I get the error invalid syntax (<unknown>, line 1) (four times per polygon in the Builder file, more on that later). However, despite the error, the JavaScript translation succeeds, my experiment runs fine both locally and online, and it syncs with Pavlovia. This seems odd given the error message.

I didn’t want to ignore the errors in case they indicated an underlying issue, so I systematically disabled components to isolate the cause. It turns out the error disappears when polygons are removed/disabled. To test further, in a version with all other polygons disabled and thus no error messages, I added a new rectangle without any interactions with code components and the errors reappeared. I also ruled out issues with the “Before Experiment” tab or experiment info settings, as disabling polygons alone prevented the error.

To confirm, I created a fresh experiment with only a single rectangular polygon, keeping all default settings. The error still appeared when converting to JavaScript, which suggested some broader issue I am unable to understand. Interestingly, the error does not appear when creating a new experiment which only contains, f.ex., a text stimuli. Has anyone else encountered this, or does anyone know why this might be happening?

2 Likes

Well done for tracking that down! I get those syntax errors all the time but, since they don’t seem to affect anything, I hadn’t yet got around to working out what was causing them.

I’ll ask @TParsons to look into it.

1 Like

Managed to track this down eventually! It looks like we do the Python → JS translation twice on the color attributes for Polygon Component, which meant on the second go around it was trying to translate JS → JS but doing so as if the input was Python, hence the error. The translator is set up to return the value unchanged and log an error when it fails, which is why the experiment ran fine but you still saw the error.

This should fix it: BF: Silence unnecessary "ERROR" log in Polygon by TEParsons · Pull Request #7091 · psychopy/psychopy · GitHub

Thanks for finding this and for investigating, it was really helpful having a starting point!