Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repl prints an error twice #27804

Open
nicolo-ribaudo opened this issue Jan 24, 2025 · 7 comments
Open

Repl prints an error twice #27804

nicolo-ribaudo opened this issue Jan 24, 2025 · 7 comments
Labels
repl related to the Read-Eval-Print-Loop functionality of Deno

Comments

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented Jan 24, 2025

Version: Deno 2.1.7

  1. Run deno to start the repl
  2. Execute for (console.log("a") of [1]);

It reports the syntax error twice:

➜ deno            
Deno 2.1.7
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> for (console.log("a") of [1]);
error: The left-hand side of an assignment expression must be a variable or a property access. at file:///repl.tsx:1:6

  for (console.log("a") of [1]);
       ~~~~~~~~~~~~~~~~

The left-hand side of an assignment expression must be a variable or a property access. at file:///repl.tsx:1:6

  for (console.log("a") of [1]);
       ~~~~~~~~~~~~~~~~

This is not a SWC bug (in their playground they only report it once), and I couldn't find other syntax errors that are printed twice.

I cannot find any other error for which this happens.

@bartlomieju bartlomieju added the repl related to the Read-Eval-Print-Loop functionality of Deno label Jan 24, 2025
@bartlomieju
Copy link
Member

I can reproduce it, it's most likely related to how we are piping transpilation errors back into the REPL. I'll look into fixing this.

@bartlomieju
Copy link
Member

Here's what I found:

  1. The transpilation actually produces two parsing diagnostics:
FoldProgram(
    ParseDiagnostics(
        ParseDiagnosticsError(
            [
                ParseDiagnostic {
                    specifier: Url {
                        scheme: "file",
                        cannot_be_a_base: false,
                        username: "",
                        password: None,
                        host: None,
                        port: None,
                        path: "/repl.tsx",
                        query: None,
                        fragment: None,
                    },
                    range: SourceRange {
                        start: SourcePos(
                            5,
                        ),
                        end: SourcePos(
                            21,
                        ),
                    },
                    kind: TS2406,
                    source: SourceTextInfo {
                        start_pos: StartSourcePos(
                            0,
                        ),
                        text: "for (console.log(\"a\") of [1]);",
                    },
                },
                ParseDiagnostic {
                    specifier: Url {
                        scheme: "file",
                        cannot_be_a_base: false,
                        username: "",
                        password: None,
                        host: None,
                        port: None,
                        path: "/repl.tsx",
                        query: None,
                        fragment: None,
                    },
                    range: SourceRange {
                        start: SourcePos(
                            5,
                        ),
                        end: SourcePos(
                            21,
                        ),
                    },
                    kind: TS2406,
                    source: SourceTextInfo {
                        start_pos: StartSourcePos(
                            0,
                        ),
                        text: "for (console.log(\"a\") of [1]);",
                    },
                },
            ],
        ),
    ),
)

What is strange is that they're identical.

  1. When trying to downcast the error here:
    match any_and_jserrorbox_downcast_ref::<ParseDiagnosticsError>(
    &err,
    ) {
    Some(diagnostics) => Ok(EvaluationOutput::Error(

    It's actually not getting downcasted and is treated as "other" error, which is just getting pretty-printed - so it prints both identical diagnostics.

@HasanAlrimawi
Copy link
Contributor

HasanAlrimawi commented Feb 10, 2025

I believe it's caused from SWC, since the errors received directly after SWC parsing and and returns, are already duplicate.

@nicolo-ribaudo
Copy link
Author

Note that the SWC repl only prints the error once, so it's something specific about how Deno is using SWC.

@HasanAlrimawi
Copy link
Contributor

HasanAlrimawi commented Feb 10, 2025

but also:
after parsing using SWC parser, and then collecting errors and printing them I noticed duplicate errors received. So it's mainly caused from SWC.
Following file path: deno_ast\src\parsing.rs
Image

Notice the errors:
Image

However, yeah it may be how Deno is using SWC as you mentioned since SWC repl only produces one error...

@HasanAlrimawi
Copy link
Contributor

I was able to make it printed once, but one of repl tests failed after this change in deno_ast/src/parsing.rs:

Image

@HasanAlrimawi
Copy link
Contributor

For reference, the repl integration test pty_syntax_error_inp failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl related to the Read-Eval-Print-Loop functionality of Deno
Projects
None yet
Development

No branches or pull requests

3 participants