{"record":{"id":"a3aacd49150474b1","repo":"quasarframework/quasar","slug":"expected-a-string-or-a-r-g-b-object-as-color","errorCode":null,"errorMessage":"Expected a string or a {r, g, b} object as color","messagePattern":"Expected a string or a (.+?) object as color","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ui/src/utils/colors/colors.js","lineNumber":206,"sourceCode":"    G = rgb.g,\n    B = rgb.b\n\n  return (\n    '#' +\n    (\n      0x1_00_00_00 +\n      (Math.round((t - R) * p) + R) * 0x1_00_00 +\n      (Math.round((t - G) * p) + G) * 0x1_00 +\n      (Math.round((t - B) * p) + B)\n    )\n      .toString(16)\n      .slice(1)\n  )\n}\n\nexport function luminosity(color) {\n  if (typeof color !== 'string' && (!color || color.r === void 0)) {\n    throw new TypeError('Expected a string or a {r, g, b} object as color')\n  }\n\n  const rgb = typeof color === 'string' ? textToRgb(color) : color,\n    r = rgb.r / 255,\n    g = rgb.g / 255,\n    b = rgb.b / 255,\n    R = r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4,\n    G = g <= 0.03928 ? g / 12.92 : ((g + 0.055) / 1.055) ** 2.4,\n    B = b <= 0.03928 ? b / 12.92 : ((b + 0.055) / 1.055) ** 2.4\n  return 0.2126 * R + 0.7152 * G + 0.0722 * B\n}\n\nexport function brightness(color) {\n  if (typeof color !== 'string' && (!color || color.r === void 0)) {\n    throw new TypeError('Expected a string or a {r, g, b} object as color')\n  }\n\n  const rgb = typeof color === 'string' ? textToRgb(color) : color","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/quasarframework/quasar/blob/4841521b5f635a971eb9e2710e5542efd194691b/ui/src/utils/colors/colors.js#L188-L224","documentation":"Quasar's luminosity(color) computes WCAG relative luminance. It accepts either a color string ('#fff', 'rgb(...)') or an {r,g,b} object (with r defined); anything else — null, undefined, numbers, or objects without r — throws this TypeError. It backs the light()/dark() contrast helpers.","triggerScenarios":"luminosity(null), luminosity(255), luminosity({ g: 0, b: 0 }) (missing r), or light(textColor, bgColor) receiving an undefined/unresolved color variable.","commonSituations":"Palette name lookup failing so getPaletteColor returns undefined which is passed on; theme colors not yet loaded at first render; passing an {r,g,b,a} object built manually that lacks r due to a typo (g/b only).","solutions":["Pass a color string instead: luminosity('#ff0000')","Ensure object inputs include all of r, g, b (numbers)","Resolve palette names first: luminosity(getPaletteColor('primary'))","Guard the call site: only compute luminosity when the color value is loaded/defined"],"exampleFix":"// before\nconst lum = luminosity(themeColor) // undefined at startup\n// after\nconst lum = themeColor ? luminosity(themeColor) : 0","handlingStrategy":"validation","validationCode":"function canComputeLuminosity(color) {\n  return typeof color === 'string'\n    || (color !== null && color !== void 0 && color.r !== void 0)\n}\nconst lum = canComputeLuminosity(c) ? luminosity(c) : 0.5","typeGuard":"function isColorLike(v) {\n  return typeof v === 'string' || (v !== null && typeof v === 'object' && v.r !== void 0)\n}","tryCatchPattern":"try {\n  lum = luminosity(color)\n} catch (err) {\n  if (err.message.includes('{r, g, b} object')) {\n    lum = 0.5 // neutral fallback until color resolves\n  } else {\n    throw err\n  }\n}","preventionTips":["Only call luminosity/light/dark after theme colors are loaded","Ensure manually built color objects include r, g and b numbers","Default unresolved palette lookups to a concrete hex","Centralize contrast computations in one guarded helper"],"tags":["colors","type-mismatch","typeerror"],"backgroundTag":"invalid-argument-type","analyzedSha":"4841521b5f635a971eb9e2710e5542efd194691b","analyzedAt":"2026-08-30T01:13:14.944Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}