{"record":{"id":"ac94c174374e760e","repo":"vitest-dev/vitest","slug":"tag-tag-name-priority-must-be-a-non-negative","errorCode":null,"errorMessage":"Tag \"${tag.name}\": priority must be a non-negative number.","messagePattern":"Tag \"(.+?)\": priority must be a non-negative number\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/config/resolveConfig.ts","lineNumber":308,"sourceCode":"      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\n    : (options.name?.label || '')\n\n  resolved.color = typeof options.name !== 'string' ? options.name?.color : undefined\n\n  if (resolved.environment === 'browser') {\n    throw new Error(`Looks like you set \"test.environment\" to \"browser\". To enable Browser Mode, use \"test.browser.enabled\" instead.`)\n  }\n\n  resolved.benchmark = {\n    ...benchmarkConfigDefaults,\n    ...resolved.benchmark,\n  }","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/config/resolveConfig.ts#L290-L326","documentation":"Vitest validates each entry in `test.tags` during config resolution. A tag may carry an optional `priority` used to order tag-based test selection; that priority must be a finite non-negative number. The guard fires when `tag.priority` is set but is either not a number (e.g. a string like \"high\") or a negative number, throwing a TypeError with the offending tag's name.","triggerScenarios":"Defining `test.tags = [{ name: 'smoke', priority: -1 }]` or `test.tags = [{ name: 'smoke', priority: 'high' }]`. Also triggered by `priority: NaN`, `priority: -0.5`, or passing an object/array as priority.","commonSituations":"Mistakenly typing priority as a string label; copy-pasting from a docs example that used a qualitative tier; computing priority from an expression that can yield a negative.","solutions":["Set `priority` to a non-negative number (0, 1, 2, ...) or omit it entirely.","If you intended qualitative tiers, map them to numbers yourself before passing to config.","Re-check the tag entry named in the error message and fix only that object."],"exampleFix":"// before\ntest: { tags: [{ name: 'smoke', priority: -1 }] }\n// after\ntest: { tags: [{ name: 'smoke', priority: 0 }] }","handlingStrategy":"validation","validationCode":"const tags = [\n  // ...your tags\n]\nfor (const t of tags) {\n  if (t.priority != null && (typeof t.priority !== 'number' || !Number.isFinite(t.priority) || t.priority < 0)) {\n    throw new Error(`Tag \"${t.name}\" has invalid priority: ${String(t.priority)}`)\n  }\n}\nexport default defineConfig({ test: { tags } })","typeGuard":"function isValidTagPriority(p: unknown): p is number {\n  return typeof p === 'number' && Number.isFinite(p) && p >= 0\n}","tryCatchPattern":"try {\n  await createVitest('test', { test: { tags } })\n} catch (err) {\n  if (err instanceof Error && /priority must be a non-negative number/.test(err.message)) {\n    // surface the offending tag and re-run with corrected config\n  }\n  throw err\n}","preventionTips":["Keep a typed TagsConfig interface and lint against unknown values.","Generate tags from a single source-of-truth table where priority is declared as number."],"tags":["config","tags","validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}