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

Coverage of types files can end up with a fatal error: Cannot read properties of undefined (reading 'endCol') #5639

Closed
6 tasks done
danielroe opened this issue Apr 30, 2024 · 2 comments · Fixed by #5642
Closed
6 tasks done
Labels
feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@danielroe
Copy link
Contributor

Describe the bug

I apologise for not submitting a minimal reproduction, but thought you'd appreciate notice of this issue while I work on creating the minimal repro.

⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot read properties of undefined (reading 'endCol')
 ❯ range.sliceRange node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:424:[55](https://github.com/nuxt/nuxt/actions/runs/8883861363/job/24393092343?pr=26922#step:7:56)
 ❯ CovSource.offsetToOriginalRelative node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:1545:20
 ❯ V8ToIstanbul._maybeRemapStartColEndCol node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:1946:92
 ❯ node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:1855:60
 ❯ node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:1853:20
 ❯ V8ToIstanbul.applyCoverage node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:1852:12
 ❯ node_modules/.pnpm/@vitest+coverage-v8@1.5.2_vitest@1.5.2_@types+node@20.12.7_happy-dom@14.7.1_sass@1.69.4_terser@5.27.0_/node_modules/@vitest/coverage-v8/dist/provider.js:2453:19

Debugging, this reveals in this code:

while (start < end) {
  let mid = (start + end) >> 1;
  if (startCol >= lines[mid].endCol) {
    start = mid + 1;
  } else if (endCol < lines[mid].startCol) {
    end = mid - 1;
  } else {
    end = mid;
    while (mid >= 0 && startCol < lines[mid].endCol && endCol >= lines[mid].startCol) {
      --mid;
    }
    start = mid + 1;
    break
  }
}

When the error occurs, start is 0, end is 1, and therefore mid initialises at 0. This means end gets set to -1 and lines[end] therefore ends up undefined.

When I log the file being processed, it seems to be one of the files which export pure types. (But note I have not been able to reproduce this naively, so 🤷.)

Reproduction

nuxt/nuxt#26922

System Info

System:
    OS: macOS 14.2.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 45.02 GB / 96.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.local/share/mise/installs/node/20/bin/node
    npm: 10.2.3 - ~/.local/share/mise/installs/node/20/bin/npm
    pnpm: 9.0.6 - ~/.local/share/mise/installs/node/20/bin/pnpm
    bun: 1.0.25 - ~/.bun/bin/bun
  Browsers:
    Chrome: 124.0.6367.92
    Safari: 17.2.1
  npmPackages:
    @vitest/coverage-v8: 1.5.2 => 1.5.2 
    vitest: 1.5.2 => 1.5.2

Used Package Manager

pnpm

Validations

@AriPerkkio
Copy link
Member

I haven't yet looked into the reproduction case or possible root cause but remembered this issue from upstream: istanbuljs/v8-to-istanbul#198

@AriPerkkio
Copy link
Member

Regression of #5457.

This condition is invalid now as all results have source maps at this point. Looks like I forgot to update this part. Files that were not run in vite-node's wrapper incorrectly apply its offset which causes v8-to-istanbul to attempt to read out of array indexes.

// If no source map was found from vite-node we can assume this file was not run in the wrapper
const wrapperLength = sources.sourceMap ? WRAPPER_LENGTH : 0

@AriPerkkio AriPerkkio added feat: coverage Issues and PRs related to the coverage feature p3-significant High priority enhancement (priority) p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage p3-significant High priority enhancement (priority) labels Apr 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants