{"record":{"id":"587ee99236e0acc8","repo":"vitest-dev/vitest","slug":"pretty-format-option-theme-has-a-key-key-w","errorCode":null,"errorMessage":"pretty-format: Option \"theme\" has a key \"${key}\" whose value \"${value}\" is undefined in ansi-styles.","messagePattern":"pretty-format: Option \"theme\" has a key \"(.+?)\" whose value \"(.+?)\" is undefined in ansi-styles\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/pretty-format/src/index.ts","lineNumber":494,"sourceCode":"    throw new Error(\n      'pretty-format: Options \"min\" and \"indent\" cannot be used together.',\n    )\n  }\n}\n\nfunction getColorsHighlight(): Colors {\n  return DEFAULT_THEME_KEYS.reduce((colors, key) => {\n    const value = DEFAULT_THEME[key]\n    const color = value && (styles as any)[value]\n    if (\n      color\n      && typeof color.close === 'string'\n      && typeof color.open === 'string'\n    ) {\n      colors[key] = color\n    }\n    else {\n      throw new Error(\n        `pretty-format: Option \"theme\" has a key \"${key}\" whose value \"${value}\" is undefined in ansi-styles.`,\n      )\n    }\n    return colors\n  }, Object.create(null))\n}\n\nfunction getColorsEmpty(): Colors {\n  return DEFAULT_THEME_KEYS.reduce((colors, key) => {\n    colors[key] = { close: '', open: '' }\n    return colors\n  }, Object.create(null))\n}\n\nfunction getPrintFunctionName(options?: OptionsReceived) {\n  return options?.printFunctionName ?? DEFAULT_OPTIONS.printFunctionName\n}\n","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/pretty-format/src/index.ts#L476-L512","documentation":"When highlight is enabled, getColorsHighlight maps each DEFAULT_THEME key to an ansi-styles color. If the configured theme value (e.g. a custom color name) does not exist in ansi-styles (no matching export with open/close strings), the build throws, naming the offending key and value.","triggerScenarios":"Passing a custom theme option with a color name not supported by ansi-styles, e.g. theme: { tag: 'purple' } where 'purple' is not an ansi-styles export; or a typo like 'reg' instead of 'red'.","commonSituations":"Customizing the highlight theme with an invalid color name; copy-pasting a color name from a different palette; ansi-styles version where the named export was removed/renamed.","solutions":[],"exampleFix":"// before\nformat(value, { highlight: true, theme: { tag: 'purple' } })\n// after\nformat(value, { highlight: true, theme: { tag: 'magenta' } })","handlingStrategy":"validation","validationCode":"import * as ansiStyles from 'ansi-styles'\nfor (const [key, value] of Object.entries(theme)) {\n  if (!ansiStyles[value] || typeof ansiStyles[value].open !== 'string') {\n    throw new Error(`invalid theme color '${value}' for key '${key}'`)\n  }\n}\nformat(value, { highlight: true, theme })","typeGuard":"function isValidThemeColor(name: string): boolean { const c = (ansiStyles as any)[name]; return !!c && typeof c.open === 'string' && typeof c.close === 'string' }","tryCatchPattern":null,"preventionTips":["Restrict theme values to documented ansi-styles exports","Validate theme at config load time","Avoid inventing color names not in ansi-styles"],"tags":["pretty-format","theme","ansi-styles","highlight"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}