{"record":{"id":"7e3f37095ed19abf","repo":"actualbudget/actual","slug":"invalid-end-date-format","errorCode":null,"errorMessage":"Invalid end date format","messagePattern":"Invalid end date format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/desktop-client/src/components/reports/spreadsheets/calendar-spreadsheet.ts","lineNumber":74,"sourceCode":"        monthUtils.firstDayOfMonth(start),\n        'yyyy-MM-dd',\n        new Date(),\n      );\n    } catch (error) {\n      console.error('Failed to parse start date:', error);\n      throw new Error('Invalid start date format');\n    }\n\n    let endDay: Date;\n    try {\n      endDay = d.parse(\n        monthUtils.lastDayOfMonth(end),\n        'yyyy-MM-dd',\n        new Date(),\n      );\n    } catch (error) {\n      console.error('Failed to parse end date:', error);\n      throw new Error('Invalid end date format');\n    }\n\n    const makeRootQuery = () =>\n      q('transactions')\n        .filter({\n          $and: [\n            { date: { $gte: d.format(startDay, 'yyyy-MM-dd') } },\n            { date: { $lte: d.format(endDay, 'yyyy-MM-dd') } },\n          ],\n        })\n        .filter({\n          [conditionsOpKey]: filters,\n        })\n        .groupBy(['date'])\n        .select(['date', { amount: { $sum: '$amount' } }]);\n\n    let expenseData;\n    try {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/desktop-client/src/components/reports/spreadsheets/calendar-spreadsheet.ts#L56-L92","documentation":"calendarSpreadsheet parses the report's 'end' month string (yyyy-MM) into a yyyy-MM-dd day string and then into a Date via date-fns parse. If that parse throws (malformed month string), the function rethrows a wrapped 'Invalid end date format' error instead of letting date-fns leak through. It exists to give report consumers a clear signal that the configured date range cannot be used to build the calendar query.","triggerScenarios":"Calling calendarSpreadsheet with an end date that is not a valid yyyy-MM month string (e.g. '2024-13', 'abc', '', '2024/05') so monthUtils.lastDayOfMonth or d.parse throws inside the try block.","commonSituations":"A saved report/dashboard has a corrupted or hand-edited start/end month in its config; a custom plugin or API integration passes an arbitrary date string instead of a month string; a locale-related refactor changes the date format passed into report builders.","solutions":["Log/inspect the end value being passed to calendarSpreadsheet and correct it to a valid 'yyyy-MM' month string","Validate the end date with a regex like /^\\d{4}-\\d{2}$/ and monthUtils.getMonth before calling calendarSpreadsheet","If the value comes from saved report config, reset or re-save the report's date range in the UI","Wrap the calendarSpreadsheet call in try/catch and fall back to a default range (e.g. current year)"],"exampleFix":"// before\ncalendarSpreadsheet(start, '2024/05', conditions, locale);\n// after\nconst end = '2024-05'; // valid yyyy-MM\nif (!/^\\d{4}-\\d{2}$/.test(end)) throw new Error('end must be yyyy-MM');\ncalendarSpreadsheet(start, end, conditions, locale);","handlingStrategy":"validation","validationCode":"const isValidMonth = (s: string) => /^\\d{4}-(0[1-9]|1[0-2])$/.test(s);\nif (!isValidMonth(end)) throw new RangeError(`end must be yyyy-MM, got: ${end}`);","typeGuard":"function isValidMonthString(v: unknown): v is string {\n  return typeof v === 'string' && /^\\d{4}-(0[1-9]|1[0-2])$/.test(v);\n}","tryCatchPattern":"try {\n  await calendarSpreadsheet(start, end, conditions, locale)(spreadsheet, setData);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid end date format') {\n    console.warn('Falling back to default range', e);\n    await calendarSpreadsheet(start, defaultEnd, conditions, locale)(spreadsheet, setData);\n  } else throw e;\n}","preventionTips":["Always store and pass report ranges as yyyy-MM month strings","Validate date config when loading saved reports, before building spreadsheets","Use monthUtils helpers rather than hand-formatting dates","Add unit tests feeding malformed end dates to report builders"],"tags":["date-parsing","reports","validation"],"backgroundTag":"invalid-date-format","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}