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

Error.stack does not use source map #2818

Closed
mitsuhiko opened this issue May 8, 2023 · 1 comment
Closed

Error.stack does not use source map #2818

mitsuhiko opened this issue May 8, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@mitsuhiko
Copy link

mitsuhiko commented May 8, 2023

What version of Bun is running?

0.5.9

What platform is your computer?

Darwin 22.4.0 arm64 arm

What steps can reproduce the bug?

I was trying to figure out reported column offsets in bun (see tc39/source-map#5 (comment)). For some reason I get wrong line numbers and columns. Reported:

function fail() {
  throw new Error();
}

function logColumn(c, e) {
  const lines = e.stack.split(/\r?\n/g);
  if (lines[0] === 'Error') {
    lines.shift();
  }
  console.log(c, parseInt(lines[1].match(/:\d+:(\d+)/)[1]));
}

try {
  /* xxxxx */fail();
} catch (e) {
  logColumn("x", e);
}
try {
  /* ☃️☃️☃️☃️☃️ */fail();
} catch (e) {
  logColumn("☃️", e);
}
try {
  /* 🔥🔥🔥🔥🔥 */fail();
} catch (e) {
  logColumn("🔥", e);
}
try {
  /* 👩‍👩‍👧👩‍👩‍👧👩‍👩‍👧👩‍👩‍👧👩‍👩‍👧 */fail();
} catch (e) {
  logColumn("👩‍👩‍👧", e);
}

What is the expected behavior?

Expected

x 14
☃️ 19
🔥 19
👩‍👩‍👧 49

What do you see instead?

x 7
☃️ 7
🔥 7
👩‍👩‍👧 7

Additional information

If you add some print on the lines you can see that not just the columns are wrong, the lines are too.

@mitsuhiko mitsuhiko added the bug Something isn't working label May 8, 2023
@Jarred-Sumner
Copy link
Collaborator

Source maps are not yet integrated into Error.prototype.stack - what you're seeing is the stack from the transpiled source in JavaScriptCore

You can use Error.captureStackTrace or console.error to get a source-mapped error

@Electroid Electroid changed the title Bun Reports Odd Error Information Error.stack does not use source map Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants