{"record":{"id":"9ccefa0942c06403","repo":"SeleniumHQ/selenium","slug":"did-not-know-how-to-convert-value-into-color","errorCode":null,"errorMessage":"Did not know how to convert ${value} into color","messagePattern":"Did not know how to convert (.+?) into color","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/lib/color.js","lineNumber":59,"sourceCode":"   * @returns {Color}\n   */\n  static fromString(value) {\n    const v = String(value)\n    for (const conv of [\n      Color.#fromRgb,\n      Color.#fromRgbPct,\n      Color.#fromRgba,\n      Color.#fromRgbaPct,\n      Color.#fromHex6,\n      Color.#fromHex3,\n      Color.#fromHsl,\n      Color.#fromHsla,\n      Color.#fromNamed,\n    ]) {\n      const c = conv(v)\n      if (c) return c\n    }\n    throw new Error(`Did not know how to convert ${value} into color`)\n  }\n\n  /**\n   * Sets opacity (alpha channel).\n   * @param {number} alpha\n   */\n  setOpacity(alpha) {\n    this.alpha_ = Color.#clamp01(alpha)\n  }\n\n  /**\n   * @returns {string} e.g. \"rgb(255, 0, 0)\"\n   */\n  asRgb() {\n    return `rgb(${this.red_}, ${this.green_}, ${this.blue_})`\n  }\n\n  /**","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/color.js#L41-L77","documentation":"Thrown by Color.fromString() when the input does not match any supported color format. The static method tries converters for rgb, rgb%, rgba, rgba%, hex6, hex3, hsl, hsla, and named CSS colors in sequence; if none succeed, this error fires with the original value.","triggerScenarios":"Passing a color in an unsupported format such as oklch(), color(display-p3 ...), or device-cmyk(). Passing a malformed string, an empty string, or a string with trailing whitespace/units. Passing a CSS variable reference like var(--color).","commonSituations":"Modern CSS color formats not yet supported by the parser; reading computed styles that return unexpected formats; typos in hex codes; localized or non-standard color names; 'transparent' or 'currentColor'.","solutions":["Normalize the color to a supported format (hex #rrggbb or rgb(r,g,b)) before calling fromString().","Trim whitespace and validate the format against a known pattern first.","Use a dedicated CSS color parsing library for modern formats (oklch, color()) and pass the rgb equivalent.","Handle 'transparent' and 'currentColor' as special cases before conversion."],"exampleFix":"// before\nColor.fromString('oklch(0.5 0.2 240)')\n// after\nColor.fromString('#3a7bd5') // convert to hex first","handlingStrategy":"validation","validationCode":"const SUPPORTED_COLOR_RE = /^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})|rgb\\(|rgba\\(|hsl\\(|hsla\\(|[a-z]+)$/i\nfunction isLikelySupportedColor(value) {\n  return typeof value === 'string' && SUPPORTED_COLOR_RE.test(value.trim())\n}\nif (!isLikelySupportedColor(colorStr)) {\n  throw new Error(`Unsupported color format: ${colorStr}. Use hex or rgb().`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize modern CSS colors (oklch, color()) to hex or rgb before calling Color.fromString().","Trim whitespace and validate the format against known patterns first.","Handle special values like 'transparent' and 'currentColor' before conversion.","Log unsupported values to catch format mismatches during testing."],"tags":["color","validation","parsing","css"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}