{"record":{"id":"678e04f73f9f7fce","repo":"juspay/hyperswitch","slug":"invalid-color-value","errorCode":null,"errorMessage":"Invalid color value","messagePattern":"Invalid color value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/router/src/core/payment_link/payment_link_initiate/payment_link.js","lineNumber":127,"sourceCode":"    len = 2;\n  }\n  return (new Array(len).join(\"0\") + str).slice(-len);\n}\nfunction hexToRgbArray(hex) {\n  if (hex.slice(0, 1) === \"#\") hex = hex.slice(1);\n  var RE_HEX = /^(?:[0-9a-f]{3}){1,2}$/i;\n  if (!RE_HEX.test(hex)) throw new Error('Invalid HEX color: \"' + hex + '\"');\n  if (hex.length === 3) {\n    hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];\n  }\n  return [\n    parseInt(hex.slice(0, 2), 16),\n    parseInt(hex.slice(2, 4), 16),\n    parseInt(hex.slice(4, 6), 16),\n  ];\n}\nfunction toRgbArray(c) {\n  if (!c) throw new Error(\"Invalid color value\");\n  if (Array.isArray(c)) return c;\n  return typeof c === \"string\" ? hexToRgbArray(c) : [c.r, c.g, c.b];\n}\nfunction getLuminance(c) {\n  var i, x;\n  var a = [];\n  for (i = 0; i < c.length; i++) {\n    x = c[i] / 255;\n    a[i] = x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);\n  }\n  return 0.2126 * a[0] + 0.7152 * a[1] + 0.0722 * a[2];\n}\nfunction invertToBW(color, bw, asArr) {\n  var DEFAULT_BW = {\n    black: \"#090302\",\n    white: \"#FFFFFC\",\n    threshold: Math.sqrt(1.05 * 0.05) - 0.05,\n  };","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/juspay/hyperswitch/blob/9b8b89dc378b62c9a6feda647bad4719d2de7699/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js#L109-L145","documentation":"Thrown by toRgbArray() in the vendored invert-color code inside the payment-link page. It fires when the colour argument is falsy (null, undefined, empty string, 0) before the hex parsing in hexToRgbArray() is even attempted. In this page invert() is called with paymentDetails.theme (line 330) and paymentDetails.payment_button_colour || primaryColor (line 364-365), so a missing/empty theme field is the direct cause.","triggerScenarios":"initializeEventListeners(paymentDetails) runs with paymentDetails.theme undefined or '' — e.g. a payment link created without any branding/theme, or a payment_link_details response where the theme field is absent or null.","commonSituations":"Merchants that never configured a theme (relying on a default the JS forgot to apply); partial API responses after a schema change renamed theme to something else; test fixtures for payment link creation omitting the branding object.","solutions":["Default the theme before use: var primaryColor = paymentDetails.theme || '#1a2b3c';","Ensure the payment link create/initiate API always returns a non-empty theme for the page","If configuring branding, set an explicit valid hex theme on the business/merchant profile used by the link"],"exampleFix":"// before\nfunction initializeEventListeners(paymentDetails) {\n  var primaryColor = paymentDetails.theme;\n  var contrastBWColor = invert(primaryColor, true);\n\n// after\nfunction initializeEventListeners(paymentDetails) {\n  var primaryColor = paymentDetails.theme || '#1a2b3c';\n  var contrastBWColor = invert(primaryColor, true);","handlingStrategy":"type-guard","validationCode":"// Before calling invert()/adjustLightness()\nconst primaryColor = paymentDetails.theme;\nif (!primaryColor) {\n  primaryColor = '#1a2b3c'; // branded default\n}","typeGuard":"/** @param {unknown} c @returns {c is string} */\nfunction isUsableColor(c) {\n  return typeof c === 'string' && c.length > 0;\n}","tryCatchPattern":"try {\n  contrastBWColor = invert(primaryColor, true);\n} catch (e) {\n  if (e.message === 'Invalid color value') {\n    contrastBWColor = '#ffffff';\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always default branding fields before rendering: theme || '#1a2b3c'","Make the payment link API return a non-empty theme rather than relying on the client to cope","Distinguish this falsy-input error from the format error (Invalid HEX color) when debugging"],"tags":["payment-link","branding","null-check","client-side"],"backgroundTag":null,"analyzedSha":"9b8b89dc378b62c9a6feda647bad4719d2de7699","analyzedAt":"2026-08-16T09:01:53.433Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}