{"id":"b10dfa90b62efe71","repo":"vitest-dev/vitest","slug":"vitest-range-location-filter-provided","errorCode":"VITEST_RANGE_LOCATION_FILTER_PROVIDED","errorMessage":"Found \"-\" in location filter ${filter}.  Note that range location filters are not supported.  Consider specifying the exact line numbers of your tests.","messagePattern":"Found \"-\" in location filter (.+?)\\.  Note that range location filters are not supported\\.  Consider specifying the exact line numbers of your tests\\.","errorType":"exception","errorClass":"RangeLocationFilterProvidedError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/cli/filter.ts","lineNumber":22,"sourceCode":"export function parseFilter(filter: string): FileFilter {\n  const colonIndex = filter.lastIndexOf(':')\n  if (colonIndex === -1) {\n    return { filename: filter }\n  }\n\n  const [parsedFilename, lineNumber] = [\n    filter.substring(0, colonIndex),\n    filter.substring(colonIndex + 1),\n  ]\n\n  if (/^\\d+$/.test(lineNumber)) {\n    return {\n      filename: parsedFilename,\n      lineNumber: Number.parseInt(lineNumber),\n    }\n  }\n  else if (/^\\d+-\\d+$/.test(lineNumber)) {\n    throw new RangeLocationFilterProvidedError(filter)\n  }\n  else {\n    return { filename: filter }\n  }\n}\n\nexport interface FileFilter {\n  filename: string\n  lineNumber?: undefined | number\n}\n\nexport function groupFilters(filters: FileFilter[]): Record<string, number[]> {\n  const groupedFilters_ = groupBy(filters, f => f.filename)\n  const groupedFilters = Object.fromEntries(Object.entries(groupedFilters_)\n    .map((entry) => {\n      const [filename, filters] = entry\n      const testLocations = filters.map(f => f.lineNumber)\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/cli/filter.ts#L4-L40","documentation":"Thrown by parseFilter() (code VITEST_RANGE_LOCATION_FILTER_PROVIDED) when a CLI/test filter contains a line range such as `file.test.ts:10-20`. Vitest location filters support a single exact line number (`file:42`) but not ranges; the parser detects the `\\d+-\\d+` pattern after the last colon and rejects it, suggesting exact line numbers instead.","triggerScenarios":"Passing `vitest path/to/file.test.ts:10-20` on the CLI or clicking a range in an IDE that forwards it as a filter. The regex `/^\\d+-\\d+$/` matches the post-colon segment and the error fires.","commonSituations":"IDE/editor integrations that construct range filters; users assuming range selection (like editor highlights) maps to test ranges; copying a `git blame`-style range.","solutions":["Specify a single exact line number: `vitest file.test.ts:10` (the test that starts at or covers that line runs).","Run the whole file (`vitest file.test.ts`) and use test-name filters (`-t 'name'`) to narrow further.","Update editor integrations to send a single line rather than a range."],"exampleFix":"# before\nvitest src/utils.test.ts:10-20\n# after\nvitest src/utils.test.ts:10","handlingStrategy":"validation","validationCode":"function normalizeFilter(f: string): string {\n  // strip a trailing range, keep a single line number\n  return f.replace(/:(\\d+)-\\d+$/, ':$1')\n}","typeGuard":"function isRangeFilter(f: string): boolean {\n  const i = f.lastIndexOf(':')\n  if (i === -1) return false\n  return /^\\d+-\\d+$/.test(f.slice(i + 1))\n}","tryCatchPattern":"try {\n  startVitest(...)\n} catch (e) {\n  if (e instanceof RangeLocationFilterProvidedError) {\n    // rewrite the range filter to its first line and retry\n  } else throw e\n}","preventionTips":["Pass a single exact line number after the colon in file filters.","Update editor integrations to send the cursor line, not a selection range.","Validate user-supplied filters with the isRangeFilter guard before passing them to Vitest."],"tags":[],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}