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: Vitest fails with Failed to cast callsite method 'getFileName' return value #24869

Closed
yasaichi opened this issue Aug 4, 2024 · 3 comments · Fixed by #24886
Closed

Bug: Vitest fails with Failed to cast callsite method 'getFileName' return value #24869

yasaichi opened this issue Aug 4, 2024 · 3 comments · Fixed by #24886
Labels
bug Something isn't working correctly

Comments

@yasaichi
Copy link

yasaichi commented Aug 4, 2024

Version: Deno x.x.x Commit hash: 71ca61e

Thank you for your recent effort to get Vitest working in Deno. After I saw #24825 merged, I tried it against my codebase and ran into the following error:

TypeError: Failed to cast callsite method 'getFileName' return value to correct value: BadType { actual: "v8::data::Value", expected: "v8::data::String" }.
 ❯ wrapCallSite node_modules/.pnpm/vite-node@2.0.5_@types+node@20.14.11_terser@5.31.3/node_modules/vite-node/dist/source-map.mjs:800:24
 ❯ Function.prepareStackTrace node_modules/.pnpm/vite-node@2.0.5_@types+node@20.14.11_terser@5.31.3/node_modules/vite-node/dist/source-map.mjs:857:10
 ❯ processError node_modules/.pnpm/@vitest+utils@2.0.5/node_modules/@vitest/utils/dist/error.js:94:11
 ❯ collectTests node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:784:21
 ❯ Object.runMicrotasks ext:core/01_core.js:653: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:175:21
 ❯ startTests node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:1179:17
 ❯ node_modules/.pnpm/vitest@2.0.5_@types+node@20.14.11_terser@5.31.3/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:130:11

As I could not make a minimum setup to reproduce the error, I will put some information about the environment instead.

  • Deno version: Built from source of which commit hash is 71ca61e
  • Vitest
    • Version: 2.0.5
    • Command: DENO_FUTURE=1 /path/to/deno run -A npm:vitest run
    • Config:
// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    alias: [
      {
        find: /^@app\/(.+)$/,
        replacement: './libs/$1/src/index.ts',
      },
    ],
    root: './',
  },
});

I hope it will be useful to solve the issue. Thank you in advance.

@yasaichi yasaichi changed the title Bug: Vitest fails with Failed to cast callsite method 'getFileName' return value to correct value Bug: Vitest fails with Failed to cast callsite method 'getFileName' return value Aug 4, 2024
@yasaichi
Copy link
Author

yasaichi commented Aug 4, 2024

Related to #23882.

@lucacasonato lucacasonato added bug Something isn't working correctly compile related to the `deno compile` feature labels Aug 5, 2024
@nathanwhit nathanwhit added node compat and removed compile related to the `deno compile` feature labels Aug 5, 2024
@nathanwhit nathanwhit self-assigned this Aug 5, 2024
@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented Aug 5, 2024

I was able to narrow this down to a small reproduction snippet.

Steps to reproduce

Run this script:

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

new Promise((_, reject) => {
  reject(new Error("fail").stack);
}).catch((err) => {
  console.log(err);
});

Output:

error: Uncaught (in promise) TypeError: Failed to cast callsite method 'getFileName' return value to correct value: BadType { actual: "v8::data::Value", expected: "v8::data::String" }.
  return frames.map((frame) => frame.getFileName());
                                     ^
    at file:///Users/marvinh/dev/test/deno-error2/main.ts:2:38
    at Array.map (<anonymous>)
    at Function.Error.prepareStackTrace (file:///Users/marvinh/dev/test/deno-error2/main.ts:2:17)
    at file:///Users/marvinh/dev/test/deno-error2/main.ts:6:28
    at new Promise (<anonymous>)
    at file:///Users/marvinh/dev/test/deno-error2/main.ts:5:1

Output Node:

[
  'file:///Users/marvinh/dev/test/deno-error2/foo.mjs',
  null,
  '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'
]

It seems like the actual return type of getFileName() is string | null whereas we always assume it to be a string here: https://github.com/denoland/deno_core/blob/c8181857b940c1f1a6f3e62103e9389ccb4a5f1d/core/error.rs#L1101-L1102

Version: Deno 1.45.5

@marvinhagemeister
Copy link
Contributor

Removing the node compat label because this is reproducible without importing anything node related.

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.

4 participants