{"record":{"id":"d28bd8fc762915a2","repo":"Mintplex-Labs/anything-llm","slug":"invalid-period-period-use-today-tomorro","errorCode":null,"errorMessage":"Invalid period: \"${period}\". Use \"today\", \"tomorrow\", \"week\", \"this week\", \"next week\", \"month\", \"this month\", or \"next month\".","messagePattern":"Invalid period: \"(.+?)\"\\. Use \"today\", \"tomorrow\", \"week\", \"this week\", \"next week\", \"month\", \"this month\", or \"next month\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/utils/agents/aibitat/plugins/google-calendar/events/gcal-get-upcoming-events.js","lineNumber":66,"sourceCode":"    case \"this month\":\n      startDate = new Date(today);\n      endDate = new Date(today);\n      endDate.setDate(endDate.getDate() + 30);\n      endDate.setHours(23, 59, 59, 999);\n      label = \"the next 30 days\";\n      break;\n\n    case \"next month\":\n      startDate = new Date(today);\n      startDate.setDate(startDate.getDate() + 30);\n      endDate = new Date(startDate);\n      endDate.setDate(endDate.getDate() + 30);\n      endDate.setHours(23, 59, 59, 999);\n      label = \"next month\";\n      break;\n\n    default:\n      throw new Error(\n        `Invalid period: \"${period}\". Use \"today\", \"tomorrow\", \"week\", \"this week\", \"next week\", \"month\", \"this month\", or \"next month\".`\n      );\n  }\n\n  return {\n    startDate: startDate.toISOString(),\n    endDate: endDate.toISOString(),\n    label,\n  };\n}\n\nmodule.exports.GCalGetUpcomingEvents = {\n  name: \"gcal-get-upcoming-events\",\n  plugin: function () {\n    return {\n      name: \"gcal-get-upcoming-events\",\n      setup(aibitat) {\n        aibitat.function({","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/aibitat/plugins/google-calendar/events/gcal-get-upcoming-events.js#L48-L84","documentation":"Thrown by getDateRangeForPeriod in the Google Calendar agent plugin. The switch statement only accepts a fixed set of period strings (case-insensitive); any other value hits the default branch and throws with a message listing all valid options. This guards the date-range computation that feeds the calendar events API call.","triggerScenarios":"Calling gcal-get-upcoming-events with a period argument that is not one of: today, tomorrow, week, this week, next week, month, this month, next month. Common when the LLM passes a free-form string like 'this weekend', 'soon', '3 days', or a localized term.","commonSituations":"Agent interprets a natural-language time request and passes an unsupported value; user types a custom period in chat; a different plugin version added new periods that this version does not recognize; whitespace or casing handled but not synonyms.","solutions":["Use only one of the documented period values: today, tomorrow, week, this week, next week, month, this month, next month.","Map free-form user input to a valid period before calling the tool — normalize synonyms like '7 days' to 'week'.","If you need a custom range, modify getDateRangeForPeriod to accept an ISO date pair or add a new case.","Ensure the period string is trimmed and lowercased before the switch (the code lowercases but does not trim)."],"exampleFix":"// before\nswitch (period.toLowerCase()) {\n  // ... cases ...\n  default:\n    throw new Error(`Invalid period: \"${period}\". Use \"today\", ...`);\n}\n\n// caller-side fix — normalize before calling\nconst VALID_PERIODS = [\"today\",\"tomorrow\",\"week\",\"this week\",\"next week\",\"month\",\"this month\",\"next month\"];\nconst normalized = period.trim().toLowerCase();\nif (!VALID_PERIODS.includes(normalized)) {\n  return `Please use one of: ${VALID_PERIODS.join(\", \")}`;\n}\n// pass normalized to the tool","handlingStrategy":"validation","validationCode":"const VALID_PERIODS = [\n  \"today\", \"tomorrow\",\n  \"week\", \"this week\", \"next week\",\n  \"month\", \"this month\", \"next month\"\n];\nconst normalized = (period || \"\").trim().toLowerCase();\nif (!VALID_PERIODS.includes(normalized)) {\n  throw new Error(`Invalid period. Valid options: ${VALID_PERIODS.join(\", \")}`);\n}\n// safe to call getDateRangeForPeriod(normalized)","typeGuard":"/** @param {string} p */\nfunction isValidPeriod(p) {\n  const valid = [\"today\",\"tomorrow\",\"week\",\"this week\",\"next week\",\"month\",\"this month\",\"next month\"];\n  return typeof p === \"string\" && valid.includes(p.trim().toLowerCase());\n}","tryCatchPattern":"try {\n  const range = getDateRangeForPeriod(period);\n  // use range.startDate, range.endDate\n} catch (e) {\n  if (e.message.startsWith(\"Invalid period\")) {\n    // Fall back to a default period and inform the user\n    const range = getDateRangeForPeriod(\"week\");\n    return { ...range, warning: `Unknown period \"${period}\", defaulting to week.` };\n  }\n  throw e;\n}","preventionTips":["Normalize user input to lowercased, trimmed values before passing.","Map common synonyms (e.g. '7 days' -> 'week') at the caller layer.","Document the exact accepted values in the tool's description for the LLM.","Default to a safe period rather than throwing when the input is ambiguous."],"tags":["google-calendar","validation","date-range","agent-tool","user-input"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}