{"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":280,"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":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/config/resolveConfig.ts#L262-L298","documentation":"Thrown when a tag's `priority` field is present but is not a number, or is a negative number. Priority controls tag evaluation ordering and must be a non-negative numeric value. The guard at resolveConfig.ts:279 rejects undefined-coerced values, strings, and negatives before they corrupt sort order downstream.","triggerScenarios":"Set `tags: [{ name: 'smoke', priority: -1 }]` or `tags: [{ name: 'smoke', priority: 'high' }]`. The check fires because priority is non-null and either not a number or less than 0.","commonSituations":"Treating priority as a label/string; using negative numbers to mean 'lowest'; copy-paste from another tool's schema.","solutions":["Set priority to a non-negative integer: `priority: 0` (or higher).","Remove the priority field entirely if you do not need ordering control.","If you used negatives for 'run last', invert your scheme so larger numbers run first and start at 0."],"exampleFix":"// before\ntags: [{ name: 'smoke', priority: -5 }]\n// after\ntags: [{ name: 'smoke', priority: 0 }]","handlingStrategy":"validation","validationCode":"function assertValidPriority(tags: any[]) {\n  for (const t of tags) {\n    if (t.priority != null && (typeof t.priority !== 'number' || t.priority < 0)) {\n      throw new Error(`Tag \"${t.name}\": priority must be a non-negative number, got ${JSON.stringify(t.priority)}`)\n    }\n  }\n}","typeGuard":"function hasValidPriority(tag: any): boolean {\n  return tag.priority == null || (typeof tag.priority === 'number' && tag.priority >= 0 && Number.isFinite(tag.priority))\n}","tryCatchPattern":null,"preventionTips":["Always use integer priorities >= 0.","If you need ordering, document the scheme (e.g. higher runs first).","Validate tags in a shared helper used by all configs."],"tags":["config","tags","priority","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}