{"record":{"id":"38d033f0bb5c0744","repo":"makeplane/plane","slug":"invalid-relative-amount-amountstr","errorCode":null,"errorMessage":"Invalid relative amount: ${amountStr}","messagePattern":"Invalid relative amount: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/utils/src/datetime.ts","lineNumber":424,"sourceCode":"      date: new Date(start).toISOString().split(\"T\")[0],\n    });\n    // Increment the date by 1 day (86400000 milliseconds)\n    start.setDate(start.getDate() + 1);\n  }\n\n  return dateArray;\n};\n\n/**\n * Processes relative date strings like \"1_weeks\", \"2_months\" etc and returns a Date\n * @param value The relative date string (e.g., \"1_weeks\", \"2_months\")\n * @returns Date object representing the calculated date\n */\nexport const processRelativeDate = (value: string): Date => {\n  const [amountStr, unit] = value.split(\"_\");\n  const amount = parseInt(amountStr, 10);\n  if (isNaN(amount)) {\n    throw new Error(`Invalid relative amount: ${amountStr}`);\n  }\n  const date = new Date();\n\n  switch (unit) {\n    case \"days\":\n      date.setDate(date.getDate() + amount);\n      break;\n    case \"weeks\":\n      date.setDate(date.getDate() + amount * 7);\n      break;\n    case \"months\":\n      date.setMonth(date.getMonth() + amount);\n      break;\n    default:\n      throw new Error(`Unsupported time unit: ${unit}`);\n  }\n\n  return date;","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/makeplane/plane/blob/1c8a60f858d8472aa56e29994ec1c7926da2c6ce/packages/utils/src/datetime.ts#L406-L442","documentation":"Thrown by processRelativeDate when parsing the amount portion of a relative-date token like '1_weeks'. The string is split on '_' and the first segment must parseInt to a valid number; if it is NaN (non-numeric or missing), the token is rejected. The token format is `<integer>_<unit>`.","triggerScenarios":"Calling processRelativeDate('abc_weeks'), processRelativeDate('_weeks'), or processRelativeDate('1.5_weeks') (parseFloat would work but parseInt floors — NaN only for non-numeric). Any value whose prefix is not an integer.","commonSituations":"User-typed or URL-param filter value that did not pass through parseDateFilter; storing a relative token from a different system with a different delimiter; off-by-one in a token builder that omits the amount.","solutions":["Verify the token shape is `<int>_<days|weeks|months>` before calling; route raw user input through parseDateFilter which splits on ';'.","Fix the token producer to always emit an integer amount.","Catch the error at the filter-execution boundary and fall back to ignoring the filter with a user notice."],"exampleFix":"// before\nconst d = processRelativeDate(rawValue);\n\n// after\nconst RELATIVE_RE = /^-?\\d+_(days|weeks|months)$/;\nconst d = RELATIVE_RE.test(rawValue)\n  ? processRelativeDate(rawValue)\n  : (() => { throw new Error(`Bad relative date token: ${rawValue}`); })();","handlingStrategy":"validation","validationCode":"const RELATIVE_RE = /^-?\\d+_(days|weeks|months)$/;\nfunction isValidRelativeToken(v: string): boolean { return RELATIVE_RE.test(v); }","typeGuard":"function isRelativeToken(v: string): v is `${number}_${'days'|'weeks'|'months'}` {\n  return /^-?\\d+_(days|weeks|months)$/.test(v);\n}","tryCatchPattern":"try { processRelativeDate(v); } catch (e) { if (/Invalid relative amount/.test((e as Error).message)) { /* ignore bad filter */ } else throw e; }","preventionTips":["Always route user input through parseDateFilter","Build tokens with a typed helper, not string concatenation","Allowlist amount+unit at the form boundary"],"tags":["datetime","filters","validation","parsing"],"backgroundTag":null,"analyzedSha":"1c8a60f858d8472aa56e29994ec1c7926da2c6ce","analyzedAt":"2026-08-12T14:44:31.636Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}