{"record":{"id":"70767b64ae446548","repo":"JuliusBrussee/caveman","slug":"recordoutcome-occurredat-must-be-a-valid-date","errorCode":null,"errorMessage":"recordOutcome: occurredAt must be a valid date","messagePattern":"recordOutcome: occurredAt must be a valid date","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mastra/src/index.ts","lineNumber":684,"sourceCode":"  });\n  if (evidenceRefs.length === 0) {\n    throw new Error(\"recordOutcome: evidence must contain at least one reference\");\n  }\n  if (evidenceRefs.length > MAX_EVIDENCE_REFS) {\n    throw new Error(`recordOutcome: evidence must contain at most ${MAX_EVIDENCE_REFS} references`);\n  }\n\n  const confidence = input.confidence;\n  if (typeof confidence !== \"number\" || !Number.isFinite(confidence) || confidence < 0 || confidence > 1) {\n    throw new Error(\"recordOutcome: confidence is required and must be a number within [0,1]\");\n  }\n  if (typeof input.source !== \"string\" || !OUTCOME_SOURCES.has(input.source)) {\n    throw new Error(\"recordOutcome: source is required and must be one of ci|environment|database|business_event|human\");\n  }\n\n  const occurredAt = input.occurredAt === undefined ? new Date() : new Date(input.occurredAt);\n  if (Number.isNaN(occurredAt.getTime())) {\n    throw new Error(\"recordOutcome: occurredAt must be a valid date\");\n  }\n\n  const body = JSON.stringify({\n    correlation_kind: \"task\",\n    correlation_id: taskId,\n    source: input.source,\n    observed_outcome: `${contract} ${stableStringify(input.values, \"values\")}`,\n    confidence,\n    evidence_refs: evidenceRefs,\n    occurred_at: occurredAt.toISOString(),\n  });\n\n  const doFetch: FetchLike = client.fetch ?? ((url, init) => globalFetch(url, init));\n  const response = await doFetch(\n    `${controlApiUrl}/api/v1/projects/${encodeURIComponent(projectId)}/outcomes`,\n    {\n      method: \"POST\",\n      headers: { \"content-type\": \"application/json\", authorization: `Bearer ${token}` },","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/packages/mastra/src/index.ts#L666-L702","documentation":"Thrown by recordOutcome in the Mastra integration when the outcome input's occurredAt field is not a valid date (missing, non-string, or unparseable). It fires after the evidence-reference and confidence checks, as part of the input validation chain.","triggerScenarios":"Thrown at packages/mastra/src/index.ts:684 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass occurredAt as an ISO 8601 string or a Date instance","Validate with !Number.isNaN(Date.parse(value)) before calling recordOutcome","Omit the field if the API allows defaulting to the current time"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}