{"record":{"id":"ddece76a943e6160","repo":"vitest-dev/vitest","slug":"tag-name-tag-name-is-invalid-tag-names-canno","errorCode":null,"errorMessage":"Tag name \"${tag.name}\" is invalid. Tag names cannot contain spaces.","messagePattern":"Tag name \"(.+?)\" is invalid\\. Tag names cannot contain spaces\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/config/resolveConfig.ts","lineNumber":296,"sourceCode":"  }\n\n  resolved.pool ??= 'forks'\n\n  resolved.project = toArray(resolved.project)\n  resolved.provide ??= {}\n\n  // shallow copy tags array to avoid mutating user config\n  resolved.tags = [...resolved.tags || []]\n  const definedTags = new Set<string>()\n  resolved.tags.forEach((tag) => {\n    if (!tag.name || typeof tag.name !== 'string') {\n      throw new Error(`Each tag defined in \"test.tags\" must have a \"name\" property, received: ${JSON.stringify(tag)}`)\n    }\n    if (definedTags.has(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is already defined in \"test.tags\". Tag names must be unique.`)\n    }\n    if (/\\s/.test(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is invalid. Tag names cannot contain spaces.`)\n    }\n    if (/[!()*|&]/.test(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is invalid. Tag names cannot contain \"!\", \"*\", \"&\", \"|\", \"(\", or \")\".`)\n    }\n    if (/^\\s*(?:and|or|not)\\s*$/i.test(tag.name)) {\n      throw new Error(`Tag name \"${tag.name}\" is invalid. Tag names cannot be a logical operator like \"and\", \"or\", \"not\".`)\n    }\n    if (typeof tag.retry === 'object' && typeof tag.retry.condition === 'function') {\n      throw new TypeError(`Tag \"${tag.name}\": retry.condition function cannot be used inside a config file. Use a RegExp pattern instead, or define the function in your test file.`)\n    }\n    if (tag.priority != null && (typeof tag.priority !== 'number' || tag.priority < 0)) {\n      throw new TypeError(`Tag \"${tag.name}\": priority must be a non-negative number.`)\n    }\n    definedTags.add(tag.name)\n  })\n\n  resolved.name = typeof options.name === 'string'\n    ? options.name","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/config/resolveConfig.ts#L278-L314","documentation":"Tag names cannot contain whitespace (`/\\s/`). Vitest uses tag names in CLI filters and boolean tag expressions where spaces would break tokenisation, so any whitespace is rejected with the offending name in the message.","triggerScenarios":"`{ name: 'smoke test' }`, `{ name: 'flaky\\t' }`, `{ name: 'a b' }`, or names with leading/trailing spaces from copy-paste.","commonSituations":"Pasting human-readable labels as tag names; importing tags from a spreadsheet/CSV that preserved spaces; typos with tabs/newlines.","solutions":["Use a single token: `smoke-test`, `smoke_test`, or `smokeTest`.","Trim and validate before export: `name: rawName.trim()` and assert `!/\\s/.test(name)`.","Keep a human-readable `description`/`label` field separate from the machine `name` if your config supports it."],"exampleFix":"// before\nexport default defineConfig({ test: { tags: [{ name: 'smoke test' }] } })\n\n// after\nexport default defineConfig({ test: { tags: [{ name: 'smoke-test' }] } })","handlingStrategy":"validation","validationCode":"function assertNoSpaces(name: string): void {\n  if (/\\s/.test(name)) {\n    throw new Error(`Tag name \"${name}\" must not contain whitespace`)\n  }\n}\n\nconst clean = rawTags.map(t => ({ ...t, name: t.name.trim() }))\nclean.forEach(t => assertNoSpaces(t.name))","typeGuard":"function isWhitespaceFreeName(name: string): boolean {\n  return typeof name === 'string' && !/\\s/.test(name)\n}","tryCatchPattern":null,"preventionTips":["Use kebab-case or snake_case for machine tag names.","Trim and validate tag names at config build time.","Keep human-readable labels in a separate `description` field."],"tags":["config","tags","validation","naming"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}