feat(python): show custom message if syntax error (#53040)

This commit is contained in:
Oliver Eyton-Williams
2024-01-09 04:25:07 +01:00
committed by GitHub
parent 2965341764
commit 82fea35622
3 changed files with 19 additions and 2 deletions

View File

@@ -133,7 +133,20 @@ input = __inputGen(${JSON.stringify(input ?? [])})
// Evaluates the learner's code so that any variables they define are
// available to the test.
runPython(code);
try {
runPython(code);
} catch (err) {
// We don't, yet, want user code to raise exceptions. When they do, we
// count this as a failing test.
ctx.postMessage({
err: {
message: (err as Error).message,
stack: (err as Error).stack,
syntaxError: true
}
});
return;
}
// TODO: remove the next line, creating __locals, once all the tests access
// variables directly.
runPython('__locals = globals()');