"PsychoPy encountered an unhandled internal error" when producing JS code to push to Pavlovia

**OS: Win10
**PsychoPy version: 2020.2.4
**Standard Standalone? y
**What are you trying to achieve?:
I want to run an experiment online. I used an experiment on Pavlovia as a template to develop my own experiment. I cloned the experiment onto my machine, made changed and then encountered problems when attempting to push it onto Pavlovia (please see the error the message below). The problem seems to be with generating JS code. The experiment runs fine in psychoPy, and I can push the experiment itself onto gitlab/ Pavlovia without a problem (e.g. using the sync command under the Pavlovia.org menu).

What did you try to make it work?:
I tried different ways of syncing. I first tried I tied it using the ‘Sync with web project’ button, which gave me the error below. I then tried syncing using the sync command under the Pavlovia.org menu - which worked fine - and then using “Export HTML”, at which point I got the same error message (below). I also tried using the Runner to “Run PsyhoJS task from Pavlovia” just for good measure, but of course, this doesn’t work because there is no HTML code to run. The html folder in the experiment directly is empty.

What specifically went wrong when you tried that?:
I get the following error message: PsychoPy encountered an unhandled internal error! Please send the report under “Details” to the developers with a description of what you were doing with the software when the error occurred.
Details:
Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript
makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 212, in writeScript
localDateTime, modular)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 527, in writeInitCodeJS
self.prepareResourcesJS()
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 515, in prepareResourcesJS
resourceFiles = self.exp.getResourceFiles()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 830, in getResourceFiles
condsPaths = findPathsInFile(params[‘conditionsFile’].val)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 818, in findPathsInFile
for thisFile in findPathsInFile(val):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 782, in findPathsInFile
filePath = eval(filePath)
File “”, line 0

^

SyntaxError: unexpected EOF while parsing

Thank you

Hi There,

So that we can pin down the issue, please can I check do you encounter this error when pushing another ‘dummy’ experiment to pavlovia or just this experiment?

Thanks,
Becca

Hi Becca, no I can push a dummy project without a problem, and JS is generating. In this one, I’m pretty sure the issue is that JS is not generating. Would it help if I provided the bits of custom python code in the projects and how they are being translated to JS?
Thanks

Hi There,

Aha yes that sounds like it could be the case - could you possible share the .psyexp file with us here so that your code components in context ?

Thanks,
Becca :slight_smile:

Hi Becca,
Yes, here it is: https://gitlab.pavlovia.org/cherkasovabbalab/reinforcementlearning
I made it public so you should be able to access it.
Thanks!
Mariya

Hi Becca, I don’t mean to pester you or anything like that - I just wanted to make sure you were able to access the experiment.
Thanks!
Mariya

Hi There, no - thanks for flagging. I actually still get a 404 error with the above link (but if the project is not loading to pavlovia I guess you cannot have a project to share? - in which case just the .psyexp file will be useful)

Thanks,
Becca

Hi Becca,
Here’s my .psyexp file. Thanks!
rl.psyexp (71.3 KB)

Hi there,

I think this is coming from your ‘response_code’ component in your ‘Trials’ routine.

Currently you import random on your python side and that import statement has been added to the .JS side (and imports don’t quite work that way in JS). Removing that line allows your experiment to compile to JS.

Random is actually imported automatically in psychopy, so you don’t need to import it. The problem then is that you won’t be able to use random.choice online as you can do locally. To fix that try this:

  1. remove the import random line from your code component as mentioned above.

  2. add a code component to your ‘instructions’ routine and set code type to be ‘JS’

add the following

choose = function choose(choices) {
  var index = Math.floor(Math.random() * choices.length);
  return choices[index];
}
  1. back in your response_code component, change code type to ‘both’.
  2. on the right hand side of this component, change any mention of random.choice to ‘choose’ (this will use your new JS function instead of trying to call the python method that won’t work online).

Let us know how you get on,
Becca

Hi Rebecca,
Thank you so much for your help! And it took me so long to try this out - crazy time of year. Unfortunately, this does not work. The experiment either isn’t using the choose function (or it doesn’t run correctly). Either way, it can’t seem to determine ‘condition’ - error message below when I try to sync with Pavlovia. I’ve tried putting the JS choice function in under ‘begin experiment’ and ‘before experiment’ - does not seem to make a difference. Also, the importing random in python in psychopy does appear to be necessar - the experiment does not run without it - but that makes no difference for the JS component evaluating condition. I’ve attached my file rl.psyexp file with the changes you suggested in case I made some mistake I just can’t spot.
Thanks again!
Mariya

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 782, in findPathsInFile
filePath = eval(filePath)
File “”, line 1, in
NameError: name ‘condition’ is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 1221, in onPavloviaSync
self.fileExport(htmlPath=htmlPath)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript
makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 212, in writeScript
localDateTime, modular)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 527, in writeInitCodeJS
self.prepareResourcesJS()
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 515, in prepareResourcesJS
resourceFiles = self.exp.getResourceFiles()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 830, in getResourceFiles
condsPaths = findPathsInFile(params[‘conditionsFile’].val)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 796, in findPathsInFile
files.extend(findPathsInFile(str(condFile)))
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 818, in findPathsInFile
for thisFile in findPathsInFile(val):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 782, in findPathsInFile
filePath = eval(filePath)
File “”, line 0

^

SyntaxError: unexpected EOF while parsing

rl.psyexp (72.7 KB)

Hi There,

Sorry to hear you are still experiencing this difficulty.

I just downloaded your .psyexp file and pushed it to pavlovia without any error messages, perhaps this is a version issue - I notice that you are running 2020.2.4 - please could I check what happens if you upgrade to 2020.2.6 and try to sync then? https://github.com/psychopy/psychopy/releases

A couple of other things to note from checking out your psyexp file here:

  1. I notice that your ‘choose’ function is in the ‘Before Experiment tab’ - you might want to also move that to the ‘Before Experiment tab’ as you want to define the function at the start of the experiment rather than before the experiment starts :slight_smile:
  2. your ‘trials’ loop is expecting the variable ‘condition’ but I can’t see where in your experiment before the trials loop the variable ‘condition’ is created. Is it possible that you meant to add a code component to your instructions routine to set this, or add a field called ‘condition’ to your start gui (in which case you would want the conditions field of your ‘trials’ routine to read as $expInfo[‘conditions’]+.xlsx

Thanks,

Becca

Hi Rebeca,
This was partly a version issue - when I used a 2020.2.6 version, I was able to push to Pavlovia. Unfortunately, there is still no JS code being generated. There is no html folder on the remote, and the html folder on my local machine is empty. Based on the last_app_load.log, it looks like an issue with the name ‘condition’ not being defined, which is the output of the JS ‘choose’ function. Not sure if this has to do with the function or what you pointed out in your second point re the ‘condition’ variable. This variable is defined in the code component of the Trial routine, Begin experiment and yields the names of condition excel files before .xlsx. The Condition field in the Trials loop calls the $condition + .xlsx. This works just fine in psychopy to randomize my conditions. But perhaps it’s a problem in JS?
Thanks again,
Mariya

Hi There,

So the html folder is not automatically generated in later releases (it was duplicating resources and the space used on the server), but this should be fine so long as there is a .js file.

Is it that the .js file is not generated or that this won’t run online because it cannot find your variable ‘condition’ - if the later, have you tried defining the condition in the ‘before experiment’ tab for the JS side of your code? (will need to change code type to be ‘both’ before editing).

Thanks,
Becca

Hi Becca,
It’s the .js file not generating. I tried putting “condition” in the “before experiment” tab but it makes no difference.
Thanks,
Mariya

Hi Mariya,

Interesting, OK so here is the version of your task that I pushed to pavlovia https://gitlab.pavlovia.org/lpxrh6/rl_debug are you able to fork it and check that these copies are identical? The .js file is exported for me on this, I am now running 2020.2.8 on windows.

Thanks,
Becca

Hi Rebecca,
I forked, cloned and checked it - of course, the copies are not identical because the one you pushed doesn’t have the “choose” function in JS (it’s the previous version of my experiment), and “condition” in js is being translated from python. But it is strange that even so, the version you push is able to generate JS code, and my version can’t. I’ve tried making the above modifications to the cloned task and pushing them back, but it doesn’t push - the commit doesn’t register. I’ve attached the most recent version of my .psyexp in case that helps.
Thanks, and sorry this is so strange and difficult…
Mariya

bandit.psyexp (71.3 KB)

Hi There,

So, this project does also compile for me https://pavlovia.org/lpxrh6/bandit_debug (although I noticed a syntax error as random is still being imported in your code component, you don’t need to import random as it is imported automatically in python, and it doesn’t exist in JS).

To confirm, when you try to push to pavlovia you do not recieve any error message, and there is no html folder that contains the file bandit.js?

Another idea, is it possible that this is on your gitlab page but not showing on your pavlovia dashboard. To check that, click on one of your other experiments and select ‘view code’ then from gitlab select projects (top right corner) > your projects - please can you feed back to me if the project name appears there but does not appear on your dashboard?

Thanks,
Becca

Hi Becca,
The project name is on the dashboard. The image below shows it in gitlab (no js code) with yesterday’s commit. When I push to Pavlovia, there is no error message, just no js code being generated. There is an html folder that’s created on my local machine, but it’s empty (second image below). Regarding that error you’re mentioning related to importing random - the experiment doesn’t run in psychopy without it, so random doesn’t seem to be importing automatically at least for my python version (3.6.6). That’s why I felft it in on the python side of things. But either way, it shouldn’t affect JS because the JS component is supposed to be using the JS “choose” function anyhow.
Thanks,
Mariya


image

Hi Mariya,

To clarify, when you try to push your project, does it still have the random import. I understand that you say this is needed to run locally, but previously this was what was stopping the .js file being written, and removal of that allowed the .js file to compile.

When you try pushing it does it still have the random function in it?

Thanks,
Becca

Please can you add me to that exact gitlab folder you are working in? my username is lpxrh6.

Hi Becca,
I added you to the project. I tried pushing both with and without ‘import random’. It doesn’t make a difference on my end - there is no JS code being generated either way. And there is no error message either with or without:

Pulling changes from remote…
Already up to date.
done
Pushing changes from remote…
done
Successful sync at: 00:15:30, took 3.545s

Thanks!
Mariya