{"record":{"id":"ffe596fd743f43c2","repo":"rohitg00/agentmemory","slug":"invalid-dateto-filter-dateto","errorCode":null,"errorMessage":"Invalid dateTo: ${filter.dateTo}","messagePattern":"Invalid dateTo: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/functions/audit.ts","lineNumber":107,"sourceCode":"  const all = await kv.list<AuditEntry>(KV.audit);\n  let entries = [...all].sort(\n    (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),\n  );\n\n  if (filter?.operation) {\n    entries = entries.filter((e) => e.operation === filter.operation);\n  }\n  if (filter?.dateFrom) {\n    const from = new Date(filter.dateFrom).getTime();\n    if (Number.isNaN(from)) {\n      throw new Error(`Invalid dateFrom: ${filter.dateFrom}`);\n    }\n    entries = entries.filter((e) => new Date(e.timestamp).getTime() >= from);\n  }\n  if (filter?.dateTo) {\n    const to = new Date(filter.dateTo).getTime();\n    if (Number.isNaN(to)) {\n      throw new Error(`Invalid dateTo: ${filter.dateTo}`);\n    }\n    entries = entries.filter((e) => new Date(e.timestamp).getTime() <= to);\n  }\n\n  return entries.slice(0, filter?.limit || 100);\n}\n","sourceCodeStart":89,"sourceCodeEnd":114,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/functions/audit.ts#L89-L114","documentation":"queryAudit filters audit entries by an optional dateTo bound. If the value cannot be parsed by new Date() (NaN result), the library throws instead of silently returning wrong results. Same validation family as the dateFrom error, but for the upper bound of the time range.","triggerScenarios":"Calling queryAudit (via entries/entriesBefore or the audit MCP/REST surface) with filter.dateTo set to an unparseable string like 'tomorrow', '2024-13-01', or a locale-formatted date.","commonSituations":"Constructing ranges from user CLI input without validation; passing millisecond timestamps as numbers coerced to weird strings; i18n formatting of dates before sending.","solutions":["Pass dateTo as an ISO 8601 string, e.g. '2024-01-31T23:59:59.999Z'.","Validate parseability with new Date(value) before the call.","For 'now' bounds, generate the value with new Date().toISOString() on the caller side.","Log the raw value to spot silent corruption (empty string, undefined stringified)."],"exampleFix":"// before\n{ dateTo: String(endMs) }\n// after\n{ dateTo: new Date(endMs).toISOString() }","handlingStrategy":"validation","validationCode":"function assertIsoDate(v: string, label: string): string {\n  const t = new Date(v).getTime();\n  if (Number.isNaN(t)) throw new Error(`${label} is not a valid date: ${v}`);\n  return new Date(t).toISOString();\n}\nconst dateTo = assertIsoDate(input.dateTo, 'dateTo');","typeGuard":"function isParseableDate(v: unknown): v is string {\n  return typeof v === 'string' && !Number.isNaN(new Date(v).getTime());\n}","tryCatchPattern":"try {\n  return await queryAudit({ dateTo });\n} catch (e) {\n  if (String(e.message).startsWith('Invalid date')) return { entries: [], hint: 'use ISO 8601 dates' };\n  throw e;\n}","preventionTips":["Use Date.prototype.toISOString() for all API date fields.","Validate both range bounds together before calling.","Reject empty strings early — they parse as Invalid Date for range use.","Keep date normalization in one shared helper."],"tags":["validation","audit","date-parsing"],"backgroundTag":"invalid-date-format","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}