Skip to content

errors: display original symbol name

Rodrigo Muino Tomonari requested to merge github/fork/bcoe/symbol-names into master

If symbol names array has been populated in source map, include original symbol name in error message.

Fixes https://github.com/nodejs/node/issues/35325


What is this?

This PR uses the optional symbol names array described in the V3 source map spec to provide additional context about an error's call site.

Take this example from #35325 (closed):

const functionA = () => {
  functionB()
}

const functionB = () => {
  functionC()
}

const functionC = () => {
  functionD()
}

const functionD = () => {
  throw new Error('Uh oh')
}

functionA()

The stack trace before this change is as follows:

Error: Uh oh
    at o (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:970)
        -> /Users/bencoe/oss/node-sourcemap-repro/dist/webpack:/index.js:14:9
    at n (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:952)
        -> /Users/bencoe/oss/node-sourcemap-repro/dist/webpack:/index.js:10:3
    at r (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:940)

It's stack trace after this change is:

webpack:///index.js:14
  throw new Error('Roh Ruh')
        ^

Error: Roh Ruh
    at o (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:970)
        -> at functionD (webpack:///index.js:14:9)
    at n (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:952)
        -> at functionC (webpack:///index.js:10:3)
    at r (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:940)
        -> at functionB (webpack:///index.js:6:3)
    at Object.<anonymous> (/Users/bencoe/oss/node-sourcemap-repro/dist/main.js:1:992)
        -> at call (webpack:///index.js:2:3)

Edit: this implementation should now match source-map-support.

CC: @schuay, @LinusU, @michael-wolfenden, @sokra

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading