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

Bug: frame.getScriptNameOrSourceURL() missing on Error #24898

Closed
marvinhagemeister opened this issue Aug 5, 2024 · 1 comment · Fixed by #24907
Closed

Bug: frame.getScriptNameOrSourceURL() missing on Error #24898

marvinhagemeister opened this issue Aug 5, 2024 · 1 comment · Fixed by #24907
Labels
bug Something isn't working correctly

Comments

@marvinhagemeister
Copy link
Contributor

Seems like we missed one: .getScriptNameOrSourceURL(). Interestingly this API is not documented on https://v8.dev/docs/stack-trace-api . This causes vitest to throw an error.

Steps to reproduce

Error.prepareStackTrace = (err, frames) => {
  return frames.map((frame) => {
    return frame.getScriptNameOrSourceURL();
  });
};

console.log(new Error("fail").stack);

Output Deno:

error: Uncaught (in promise) TypeError: frame.getScriptNameOrSourceURL is not a function
    return frame.getScriptNameOrSourceURL();
                 ^
    at file:///Users/marvinh/dev/test/deno-error2/foo.mjs:3:18
    at Array.map (<anonymous>)
    at Function.Error.prepareStackTrace (file:///Users/marvinh/dev/test/deno-error2/foo.mjs:2:17)
    at file:///Users/marvinh/dev/test/deno-error2/foo.mjs:7:31

Output Node:

[
  'file:///Users/marvinh/dev/test/deno-error2/foo.mjs',
  'node:internal/modules/esm/module_job',
  'node:internal/modules/esm/loader',
  'node:internal/modules/run_main'
]

Output Chrome:

['']

Version: Deno 1.45.5

@yasaichi
Copy link

yasaichi commented Aug 5, 2024

This issue is just what I am going to create. I ran into the same error when I tested #24869 against my codebase using Vitest.

TypeError: frame.getScriptNameOrSourceURL is not a function
 ❯ wrapCallSite node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite-node/dist/source-map.mjs:800:47
 ❯ Function.prepareStackTrace node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite-node/dist/source-map.mjs:857:10
 ❯ processError node_modules/.pnpm/@[email protected]/node_modules/@vitest/utils/dist/error.js:94:11
 ❯ collectTests node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:784:21
 ❯ Object.runMicrotasks ext:core/01_core.js:690:26
 ❯ processTicksAndRejections ext:deno_node/_next_tick.ts:53:10
 ❯ runNextTicks ext:deno_node/_next_tick.ts:71:3
 ❯ eventLoopTick ext:core/01_core.js:181:21
 ❯ startTests node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:1179:17
 ❯ node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:130:11
// node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite-node/dist/source-map.mjs
function wrapCallSite(frame, state) {
  if (state === void 0) {
    state = { nextPosition: null, curPosition: null };
  }
  if (frame.isNative()) {
    state.curPosition = null;
    return frame;
  }
  const source = frame.getFileName() || frame.getScriptNameOrSourceURL(); // <- here

marvinhagemeister added a commit to denoland/deno_core that referenced this issue Aug 6, 2024
Both Chrome and Node have a `getScriptNameOrSourceUrl()` method on the
`CallSite` prototype. We didn't have that which causes an error in
`vitest`, see denoland/deno#24898
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants