{"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":268,"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":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/config/resolveConfig.ts#L250-L286","documentation":"Thrown during tag validation when a tag name contains whitespace (matches /\\s/). Tag selection expressions are tokenized on whitespace, so a name containing spaces would be ambiguous to parse; such names are rejected to keep the filter grammar well-defined.","triggerScenarios":"Defining a tag like `{ name: 'slow tests' }` or `{ name: 'unit core' }`, or reading tag names from user data/file names that contain spaces.","commonSituations":"Tag names derived from human-readable labels, test suite titles, or spreadsheet columns without normalization.","solutions":["Remove spaces from tag names: use 'slow-tests', 'slowTests', or 'slow'.","Normalize external strings (replace \\s+ with '-' or '_') before assigning as tag names."],"exampleFix":"// before\nexport default defineConfig({ test: { tags: [{ name: 'slow tests' }] } })\n// after\nexport default defineConfig({ test: { tags: [{ name: 'slow-tests' }] } })","handlingStrategy":"validation","validationCode":"if (/\\s/.test(name)) {\n  throw new Error(`tag name contains spaces: ${name}`)\n}","typeGuard":"function isValidTagName(name: string): boolean {\n  return name.length > 0 && !/\\s/.test(name) && !/[!()*|&]/.test(name)\n    && !/^\\s*(?:and|or|not)\\s*$/i.test(name)\n}","tryCatchPattern":null,"preventionTips":["Use kebab-case or snake_case tag names.","Normalize external strings (replace whitespace) before using as tag names.","Validate names with isValidTagName in config builders."],"tags":[],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}