Skip to content

Commit 519c388

Browse files
committed
OSWebWriter: raise OSWebCompatibilityError when script contains unsupported syntax
1 parent 2cfc97b commit 519c388

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

opensesame_extensions/osweb/oswebext/oswebext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def event_osweb_run(self, fullscreen=False, subject_nr=0,
293293
welcome_text=cfg.oswebext_welcome_text,
294294
external_js=self._external_js(),
295295
intro_click=cfg.oswebext_intro_click)
296-
except PythonToJavaScriptError as e:
296+
except (OSWebCompatibilityError, PythonToJavaScriptError) as e:
297297
return e
298298
else:
299299
webbrowser.open('file://{}'.format(index_path))

osweb/oswebwriter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from libopensesame.osexpfile import OSExpWriter
2121
from libopensesame.oslogging import oslogger
2222
from metapensiero.pj.__main__ import transform_string as py2js
23-
from .oswebexceptions import PythonToJavaScriptError
23+
from .oswebexceptions import PythonToJavaScriptError, OSWebCompatibilityError
2424
import re
2525

2626
RE_VAR = re.compile('(?<!\w)var\.', re.MULTILINE)
@@ -68,7 +68,14 @@ def parse_cmd(self):
6868
def script(self):
6969
script = self._exp.to_string()
7070
for m in RE_RUN_IF.finditer(script):
71-
_, (item, cond), _ = self.parse_cmd(m.group('cmd'))
71+
try:
72+
_, (item, cond), _ = self.parse_cmd(m.group('cmd'))
73+
except ValueError:
74+
# This mainly happens for coroutines, which have a slightly
75+
# deviant run statement
76+
raise OSWebCompatibilityError(
77+
f'The following OpenSesame script is not supported in '
78+
f'OSWeb:\n\n```\n{m.group("cmd")}\n```')
7279
cond = self.transform(cond)
7380
cmd = self.create_cmd('run', (item, cond))
7481
oslogger.debug(f'rewriting {m.group("cmd")} to {cmd}')

0 commit comments

Comments
 (0)