pyodide: Bug: Syntax error handling in console.html

Syntax errors in console.html are not printed immediately, only after the next command is submitted. E.g., type 1+<ENTER> into console.html.

I think this was introduced in #1125. I investigated but I can’t figure out why it’s happening. Any ideas @casatir?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (20 by maintainers)

Most upvoted comments

The why it happens only for syntax errors (and not runtime errors) can be understood with this three lines:

    const prompt = pyconsole.push(c) ? ps2 : ps1;
    term.set_prompt(prompt);
    await pyconsole.run_complete;

Execution steps for runtime errors (or even code exec without any error) are:

  1. pyconsole.push(c) returns false (code is not yet executed)
  2. prompt is set to >>>
  3. code is executed (via the run_complete promise), error is printed to stderr
  4. JQuery Terminal shows it by setting the prompt.

While for syntax error, we have:

  1. pyconsole.push(c) prints syntax error to stderr (and return false)
  2. JQuery Terminal shows it by setting the prompt
  3. prompt is erased by our call to set_prompt
  4. run_complete is a dummy promise so the await has no effect.

I think I got it. In console.html, we continuously set the prompt:

async function interpreter(command) {
    // multiline should be splitted (usefull when pasting)
    term.pause();
    for( const c of command.split('\n') ) {
        const prompt = pyconsole.push(c) ? ps2 : ps1;
        term.set_prompt(prompt);
        await pyconsole.run_complete;
    }
    term.resume();
}

which disturb echo_newline.js since it also set the prompt…