{"record":{"id":"f46cde806db65fc3","repo":"quasarframework/quasar","slug":"expected-offset-to-be-between-1-and-1","errorCode":null,"errorMessage":"Expected offset to be between -1 and 1","messagePattern":"Expected offset to be between -1 and 1","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ui/src/utils/colors/colors.js","lineNumber":267,"sourceCode":"    g2 = rgb2.g / 255,\n    b2 = rgb2.b / 255,\n    a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\n    a = a1 + a2 * (1 - a1),\n    r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\n    g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\n    b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\n\n  const ret = { r, g, b, a: Math.round(a * 100) }\n  return typeof fgColor === 'string' ? rgbToHex(ret) : ret\n}\n\nexport function changeAlpha(color, offset) {\n  if (typeof color !== 'string') {\n    throw new TypeError('Expected a string as color')\n  }\n\n  if (offset === void 0 || offset < -1 || offset > 1) {\n    throw new TypeError('Expected offset to be between -1 and 1')\n  }\n\n  const { r, g, b, a } = textToRgb(color)\n  const alpha = a !== void 0 ? a / 100 : 0\n\n  return rgbToHex({\n    r,\n    g,\n    b,\n    a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\n  })\n}\n\nexport function getPaletteColor(colorName) {\n  if (typeof colorName !== 'string') {\n    throw new TypeError('Expected a string as color')\n  }\n","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/quasarframework/quasar/blob/4841521b5f635a971eb9e2710e5542efd194691b/ui/src/utils/colors/colors.js#L249-L285","documentation":"changeAlpha(color, offset) requires offset to be defined and within [-1, 1]; anything else (undefined, out-of-range numbers, non-numbers) throws this TypeError. The offset is a relative alpha adjustment: the resulting alpha is clamped into the valid range after adding the offset.","triggerScenarios":"colors.changeAlpha('#ff0000') with no offset; colors.changeAlpha('#ff0000', 1.5) or -2; passing a percentage like 50 instead of 0.5; passing a string '0.5' (fails comparison logic / undefined check for other invalid values).","commonSituations":"Misreading the API as taking an absolute 0-100 or 0-1 alpha instead of a relative -1..1 delta; forgetting the second argument; computing the offset with a formula that can exceed 1.","solutions":["Pass a number between -1 and 1, e.g. colors.changeAlpha('#ff0000', 0.5).","Convert a percentage: offset = percent / 100 (e.g. 50 -> 0.5).","Clamp computed offsets: offset = Math.min(1, Math.max(-1, computed)).","Always supply the second argument; it has no default."],"exampleFix":"// before\nconst c = colors.changeAlpha('#ff0000', 50) // throws\n// after\nconst c = colors.changeAlpha('#ff0000', 0.5)","handlingStrategy":"validation","validationCode":"const isValidOffset = (o) => typeof o === 'number' && o >= -1 && o <= 1\nif (!isValidOffset(offset)) throw new Error('offset must be a number in [-1, 1]')","typeGuard":"const isAlphaOffset = (o) => typeof o === 'number' && Number.isFinite(o) && o >= -1 && o <= 1","tryCatchPattern":"let result\ntry {\n  result = colors.changeAlpha(color, offset)\n} catch (err) {\n  if (err instanceof TypeError && /between -1 and 1/.test(err.message)) {\n    result = colors.changeAlpha(color, Math.min(1, Math.max(-1, offset ?? 0)))\n  } else throw err\n}","preventionTips":["Clamp user/computed offsets with Math.min(1, Math.max(-1, v)) before calling.","Convert percentages: offset = percent / 100.","Never omit the offset argument — it is required and has no default."],"tags":["typeerror","colors","range-validation","quasar"],"backgroundTag":"invalid-color-argument","analyzedSha":"4841521b5f635a971eb9e2710e5542efd194691b","analyzedAt":"2026-08-30T01:13:14.944Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}