{"record":{"id":"a1812fd7333466cc","repo":"quasarframework/quasar","slug":"expected-a-string","errorCode":null,"errorMessage":"Expected a string","messagePattern":"Expected a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ui/src/utils/colors/colors.js","lineNumber":29,"sourceCode":"    throw new TypeError(\n      'Expected 3 numbers below 256 (and optionally one below 100)'\n    )\n  }\n\n  a = alpha\n    ? (Math.round((255 * a) / 100) | (1 << 8)).toString(16).slice(1)\n    : ''\n\n  return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\n}\n\nexport function rgbToString({ r, g, b, a }) {\n  return `rgb${a !== void 0 ? 'a' : ''}(${r},${g},${b}${a !== void 0 ? ',' + a / 100 : ''})`\n}\n\nexport function hexToRgb(hex) {\n  if (typeof hex !== 'string') {\n    throw new TypeError('Expected a string')\n  }\n\n  if (hex.codePointAt(0) === 35) hex = hex.slice(1) // #\n\n  if (hex.length === 3) {\n    hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\n  } else if (hex.length === 4) {\n    hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\n  }\n\n  const num = Number.parseInt(hex, 16)\n\n  return hex.length > 6\n    ? {\n        r: (num >> 24) & 255,\n        g: (num >> 16) & 255,\n        b: (num >> 8) & 255,\n        a: Math.round((num & 255) / 2.55)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/quasarframework/quasar/blob/4841521b5f635a971eb9e2710e5542efd194691b/ui/src/utils/colors/colors.js#L11-L47","documentation":"Quasar's hexToRgb() requires its argument to be a string containing a hex color. It throws a TypeError when the input is not a string (number, object, null, undefined). The library validates early so downstream string operations (codePointAt, slice, length) cannot fail mysteriously.","triggerScenarios":"hexToRgb(0xff0000) (a number, not a string), hexToRgb(null), hexToRgb({ r: 1, g: 2, b: 3 }), or onEditorChange/textToRgb receiving a non-string model value and forwarding it.","commonSituations":"QColor editor/model returning an object; passing a parsed color object where a string is expected; reading color values from JSON/config that came as numbers.","solutions":["Convert numbers to a hex string first: hexToRgb('#' + num.toString(16).padStart(6, '0'))","If you already have an {r,g,b} object, skip hexToRgb and use the value directly (or rgbToString)","Add typeof checks at the input boundary of your own color utilities","Fix the data source (config/model) so color values are stored as strings like '#ff0000'"],"exampleFix":"// before\nconst rgb = hexToRgb(props.colorNumber)\n// after\nconst rgb = typeof props.colorNumber === 'number'\n  ? hexToRgb('#' + props.colorNumber.toString(16).padStart(6, '0'))\n  : hexToRgb(props.colorNumber)","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'string' || value.length === 0) {\n  value = '#000000' // or handle explicitly\n}\nconst rgb = hexToRgb(value)","typeGuard":"function isHexColorString(v) {\n  return typeof v === 'string' && /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v.trim())\n}","tryCatchPattern":"try {\n  rgb = hexToRgb(color)\n} catch (err) {\n  if (err.message === 'Expected a string') {\n    rgb = { r: 0, g: 0, b: 0 }\n  } else {\n    throw err\n  }\n}","preventionTips":["Store colors as strings ('#rrggbb') in config, JSON and models","Convert numeric colors to '#'+toString(16) before any Quasar color utility","Initialize QColor v-model refs with a valid hex string, never null","Use TypeScript/JSDoc so non-string arguments are flagged statically"],"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"}