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

vscode node debugger parses inline sourcemap incorrectly #35978

Closed
t83714 opened this issue Oct 10, 2017 · 19 comments
Closed

vscode node debugger parses inline sourcemap incorrectly #35978

t83714 opened this issue Oct 10, 2017 · 19 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verified Verification succeeded
Milestone

Comments

@t83714
Copy link

t83714 commented Oct 10, 2017

  • VSCode Version: 1.17.0
  • OS Version: macOS 10.13

Steps to Reproduce:

  1. Create an empty folder
  2. Add package.json with the following content:
{
  "name": "vscode-issue",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@std/esm": "^0.11.3"
  },
  "@std/esm": {
    "esm": "all",
    "cjs": true
  }
}
  1. Create file index.js with the following content:
import path from "path";

console.log(path.resolve(__dirname, ".."));
  1. Configure launch.json as:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceRoot}/index.js",
            "runtimeArgs": [
                "-r","@std/esm"
            ]
        }
    ]
}
  1. npm install
  2. Press F5 to start vscode debugger
  3. You will see the following error:
Debugging with inspector protocol because Node.js v8.6.0 was detected.
node --inspect-brk=36570 -r @std/esm index.js 
Debugger listening on ws://127.0.0.1:36570/a572c7ff-3251-4ae3-b74c-5abe01c3b73c
Debugger attached.
SourceMaps.getMapForGeneratedPath: exception while processing path: /Users/user/Development/vscode-issue/index.js, sourcemap: data:application/json;charset=utf-8,%7B%22version%22:3,%22sources%22:%5B%22/Users/user/Development/vscode-issue/index.js%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;AACA;AACA%22%7D
SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at new SourceMap (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/vscode-chrome-debug-core/out/src/sourceMaps/sourceMap.js:20:25)
    at sourceMapContentsP.then.contents (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/vscode-chrome-debug-core/out/src/sourceMaps/sourceMapFactory.js:53:28)
    at <anonymous>

Reproduces without extensions: Yes

It seems vscode debugger always assumes the inline sourcemap data URI is in base64 encoding (even if the ;base64 extension is not included in the data URI scheme).

This will lead to data decoding error.

@vscodebot vscodebot bot added the debug Debug viewlet, configurations, breakpoints, adapter issues label Oct 10, 2017
@isidorn isidorn assigned roblourens and unassigned isidorn Oct 10, 2017
@jdalton
Copy link

jdalton commented Oct 10, 2017

Possibly related to these lines

https://github.com/Microsoft/vscode/blob/407ce43a5e0bb079b3d0db802a2f7367c2f97c99/build/lib/util.js#L146-L153


Update:

Looks to be convert-source-map dep; thlorenz/convert-source-map#59.

@roblourens
Copy link
Member

I didn't know that was valid. convert-source-map isn't involved at all, as far as I know. I just need to update https://github.com/Microsoft/vscode-chrome-debug-core/blob/master/src/sourceMaps/sourceMap.ts#L81

@jdalton
Copy link

jdalton commented Oct 11, 2017

Oh, rad! Yep, it's allowed 😋

For more info see:

thlorenz/convert-source-map#59 (comment)
and
thlorenz/convert-source-map#48 (comment)

@roblourens roblourens added the feature-request Request for new features or functionality label Nov 26, 2017
@roblourens roblourens modified the milestones: November 2017, December 2017 Dec 4, 2017
@ramya-rao-a
Copy link
Contributor

@roblourens Moving to March since you are not here ...

@ramya-rao-a ramya-rao-a modified the milestones: February 2018, March 2018 Mar 1, 2018
@roblourens roblourens modified the milestones: March 2018, Backlog Mar 26, 2018
@jpike88
Copy link

jpike88 commented Jul 17, 2018

I'm going INSANE with this one. Any movement?

@roblourens
Copy link
Member

Is this format commonly used?

I think the right fix will be to take a dependency on that convert-source-map package.

@jpike88
Copy link

jpike88 commented Jul 17, 2018

Some more side information here:

The issue is the inlined source maps aren't being encoded properly. Here is the issue present in getMapForGeneratedPath, and what I see is that the mapPath has HTML entities used which throws everything off.

screen shot 2018-07-18 at 12 16 19 am

Going up the stack trace... It's present in onScriptParsed in chromeDebugAdapter.js...

screen shot 2018-07-18 at 12 29 17 am

@jpike88
Copy link

jpike88 commented Jul 17, 2018

Still not sure why this issue popped up... I updated a fair amount of dependencies and this happened. Does this have to do with a recent typescript update? Does anyone know of workarounds to this?

@jpike88
Copy link

jpike88 commented Jul 17, 2018

Ohhh it might have been updating @std/esm! If anyone is having this issue downgrading that will probably help things.

@jpike88
Copy link

jpike88 commented Jul 17, 2018

confirming that downgrading to esm@3.0.18 reversed this issue.

@jpike88
Copy link

jpike88 commented Jul 17, 2018

@jdalton would you happen to know the latest non-breaking version of esm that won't re-trigger this issue?

@roblourens
Copy link
Member

The encoding is valid, I just haven't gotten to supporting it since it doesn't seem to be very common.

@jpike88
Copy link

jpike88 commented Jul 18, 2018

The error is really obscure though, it might be worth putting in a note regarding this in the error output.

@jdalton
Copy link

jdalton commented Jul 18, 2018

@jpike88

The only recent change I've done to source maps is to ensure they use a file url instead of a file path (because on Windows the file path is not a valid url and caused load fails in the Node inspector).

@roblourens

It would be great not to have to base64 encode since that's processing and these source maps are generated at runtime. The encoding is just

"//# sourceMappingURL=data:application/json;charset=utf-8," +
  encodeURI(createSourceMap(filename, content))

so decoding is

decodeURI(sourceMappungURL.slice(36))

Update:

I'll prep a PR to patch getInlineSourceMapContents() with support for utf-8 encoded urls.

@roblourens
Copy link
Member

That would be fantastic, thanks.

@roblourens
Copy link
Member

@Pokute beat you to it but I'll get this into tomorrow's Insiders build.

@jdalton
Copy link

jdalton commented Jul 19, 2018

Rock, thank you!

@roblourens roblourens added the verification-needed Verification of issue is requested label Jul 31, 2018
@JacksonKearl JacksonKearl added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Jul 31, 2018
@remcohaszing
Copy link
Contributor

I just ran into this issue using VSCode 1.25.1. Just checking… should this fix have been released yet?

@jpike88
Copy link

jpike88 commented Aug 9, 2018

@remcohaszing its in insiders build, not released to the public yet

@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

9 participants