Mintplex-Labs/anything-llm · warning · Error
Invalid period: "${period}". Use "today", "tomorrow", "week"
Error message
Invalid period: "${period}". Use "today", "tomorrow", "week", "this week", "next week", "month", "this month", or "next month". What it means
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.
Source
Thrown at server/utils/agents/aibitat/plugins/google-calendar/events/gcal-get-upcoming-events.js:66
case "this month":
startDate = new Date(today);
endDate = new Date(today);
endDate.setDate(endDate.getDate() + 30);
endDate.setHours(23, 59, 59, 999);
label = "the next 30 days";
break;
case "next month":
startDate = new Date(today);
startDate.setDate(startDate.getDate() + 30);
endDate = new Date(startDate);
endDate.setDate(endDate.getDate() + 30);
endDate.setHours(23, 59, 59, 999);
label = "next month";
break;
default:
throw new Error(
`Invalid period: "${period}". Use "today", "tomorrow", "week", "this week", "next week", "month", "this month", or "next month".`
);
}
return {
startDate: startDate.toISOString(),
endDate: endDate.toISOString(),
label,
};
}
module.exports.GCalGetUpcomingEvents = {
name: "gcal-get-upcoming-events",
plugin: function () {
return {
name: "gcal-get-upcoming-events",
setup(aibitat) {
aibitat.function({View on GitHub (pinned to 526360e320)
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).
Example fix
// before
switch (period.toLowerCase()) {
// ... cases ...
default:
throw new Error(`Invalid period: "${period}". Use "today", ...`);
}
// caller-side fix — normalize before calling
const VALID_PERIODS = ["today","tomorrow","week","this week","next week","month","this month","next month"];
const normalized = period.trim().toLowerCase();
if (!VALID_PERIODS.includes(normalized)) {
return `Please use one of: ${VALID_PERIODS.join(", ")}`;
}
// pass normalized to the tool Defensive patterns
Strategy: validation
Validate before calling
const VALID_PERIODS = [
"today", "tomorrow",
"week", "this week", "next week",
"month", "this month", "next month"
];
const normalized = (period || "").trim().toLowerCase();
if (!VALID_PERIODS.includes(normalized)) {
throw new Error(`Invalid period. Valid options: ${VALID_PERIODS.join(", ")}`);
}
// safe to call getDateRangeForPeriod(normalized) Type guard
/** @param {string} p */
function isValidPeriod(p) {
const valid = ["today","tomorrow","week","this week","next week","month","this month","next month"];
return typeof p === "string" && valid.includes(p.trim().toLowerCase());
} Try / catch
try {
const range = getDateRangeForPeriod(period);
// use range.startDate, range.endDate
} catch (e) {
if (e.message.startsWith("Invalid period")) {
// Fall back to a default period and inform the user
const range = getDateRangeForPeriod("week");
return { ...range, warning: `Unknown period "${period}", defaulting to week.` };
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Key must contain only letters, numbers and underscores
- search pattern must not start with '-'
- Type "${type}" is not a valid type to sync.
- Invalid link provided
- Invalid source property provided
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/d28bd8fc762915a2.
Report an issue: GitHub.