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

computeCurrentScript() from d8 preamble fails in VS Code extension host (NodeJS) due to tabs instead of spaces for stack trace indenting #55684

Closed
DanTup opened this issue May 10, 2024 · 2 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dart2js

Comments

@DanTup
Copy link
Collaborator

DanTup commented May 10, 2024

I was trying to run some compiled Dart in a VS Code extension (which runs in a NodeJS process) using the d8 preamable file).

The computeCurrentScript function fails like this:

image

I added some logging of the regex and the stack that was captured:

      var lastMatch = null;
      do {
        console.warn(re.source);
        console.warn(stack);
        var match = re.exec(stack);
        console.warn(match);
        if (match != null) lastMatch = match;
      } while (match != null);
      return lastMatch[1];

And the output looked like this:

image

Everything appeared good but after some more debugging I found that the stack trace here has tabs and not spaces!

If I change the start of the regex from /^ *at to /^\s*at then the code works (or at least it gets further.. but I think the remaining issues are my own).

I cannot figure out why the stack traces have tabs here, but it seems like changing the space to \s here would not be breaking so I'm hopeful that it is a change that could be made. I'm happy to open a CL if someone can confirm this is a valid change.

@mraleph mraleph added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label May 11, 2024
@sigmundch
Copy link
Member

Wow, that's so bizarre!

I'm not opposed to changing it just to make it more flexible. Here is a CL to do so: https://dart-review.googlesource.com/c/sdk/+/366160

Note: while the d8 preamble is OK to use in node, the node_preamble may be a better fit. That package however has the same logic and currently uses spaces rather than \s, so it would also need to be updated.

@DanTup
Copy link
Collaborator Author

DanTup commented May 13, 2024

Here is a CL to do so: https://dart-review.googlesource.com/c/sdk/+/366160

Thanks!

Note: while the d8 preamble is OK to use in node, the node_preamble may be a better fit.

It actually turned out that the preamble completely broke all the built-in VS Code extensions. It seems like it was manipulating something global that VS Code / other extensions didn't expect that I got lots of exceptions. In the end I ditched the pre-amble and just added the minimum I needed (I think globalThis.self = globalThis.self ?? {};) for the code to run.

I don't know what the d8 in that preamble meant, I just saw someone else link to it and tried it. I'm curious what it's intended for / how it differs from the node_preamble package?

If I did need one though, I'd be concerned about depending on a package that just says "unverified uploader" and hasn't been published for 14 months - I assumed what's in the SDK would be more likely to be maintained (but that feeling is probably not based on a whole lot!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants