{"record":{"id":"b11134bfc3f2a395","repo":"JuliusBrussee/caveman","slug":"recordoutcome-values-must-be-a-non-empty-plain-ob","errorCode":null,"errorMessage":"recordOutcome: values must be a non-empty plain object","messagePattern":"recordOutcome: values must be a non-empty plain object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mastra/src/index.ts","lineNumber":650,"sourceCode":" *\n * Fails closed BEFORE any network call on a missing task id, a missing contract,\n * empty values, an evidence map that is empty or over the server's limit, a\n * confidence outside [0,1], or values that are not plain JSON. Exactly one\n * request is made — no retries — and a non-2xx response throws a\n * {@link CavemanOutcomeError} carrying the status and body verbatim.\n */\nexport async function recordOutcome(\n  client: CavemanOutcomeClient,\n  input: RecordOutcomeInput,\n): Promise<RecordOutcomeResult> {\n  const controlApiUrl = requireBaseUrl(client.controlApiUrl, \"recordOutcome: controlApiUrl\");\n  const token = requireNonEmpty(client.token, \"recordOutcome: token\");\n  const projectId = requireNonEmpty(client.projectId, \"recordOutcome: projectId\");\n  const taskId = requireNonEmpty(input.taskId, \"recordOutcome: taskId\");\n  const contract = requireNonEmpty(input.contract, \"recordOutcome: contract\");\n\n  if (!isPlainObject(input.values) || Object.keys(input.values).length === 0) {\n    throw new Error(\"recordOutcome: values must be a non-empty plain object\");\n  }\n  if (!isPlainObject(input.evidence)) {\n    throw new Error(\"recordOutcome: evidence must be a plain object\");\n  }\n  const evidenceRefs = Object.entries(input.evidence).map(([key, value]) => {\n    if (!key.trim()) throw new Error(\"recordOutcome: evidence keys must be non-empty\");\n    if (typeof value !== \"string\" && typeof value !== \"number\" && typeof value !== \"boolean\") {\n      throw new Error(`recordOutcome: evidence.${key} must be a string, number, or boolean`);\n    }\n    if (typeof value === \"number\" && !Number.isFinite(value)) {\n      throw new Error(`recordOutcome: evidence.${key} must be a finite number`);\n    }\n    const ref = `${key}:${String(value)}`;\n    if (!ref.slice(key.length + 1)) throw new Error(`recordOutcome: evidence.${key} must be non-empty`);\n    return ref;\n  });\n  if (evidenceRefs.length === 0) {\n    throw new Error(\"recordOutcome: evidence must contain at least one reference\");","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/mastra/src/index.ts#L632-L668","documentation":"recordOutcome sends outcome values plus evidence references to the Caveman control API, and it validates input client-side before the request. values must be a plain object (not an array, null, class instance, or primitive) with at least one key; an empty object would produce an outcome with no measurements, which the API rejects, so the SDK fails fast with this message.","triggerScenarios":"recordOutcome(client, { taskId, contract, values: {} }) or values: [] / values: null / values built from Object.create(null)-adjacent or class instances that fail isPlainObject.","commonSituations":"Dynamically building values from a loop that produced no entries, spreading an optional config that is undefined, or passing a Map/array because the payload schema was misread.","solutions":["Ensure values contains at least one scalar measurement, e.g. { correctness: 1 }.","Skip the recordOutcome call entirely when there is nothing to report rather than sending an empty object.","Use a plain object literal (not a class instance or array) for values."],"exampleFix":"// before\nawait recordOutcome(client, { taskId, contract, values: {} });\n// after\nif (Object.keys(values).length > 0) {\n  await recordOutcome(client, { taskId, contract, values });\n}","handlingStrategy":"validation","validationCode":"function isPlainObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === \"object\" && v !== null && !Array.isArray(v)\n    && Object.getPrototypeOf(v) === Object.prototype;\n}\n\nfunction validValues(v: unknown): boolean {\n  return isPlainObject(v) && Object.keys(v).length > 0;\n}","typeGuard":"function isPlainObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === \"object\" && v !== null && !Array.isArray(v)\n    && Object.getPrototypeOf(v) === Object.prototype;\n}","tryCatchPattern":"try {\n  await recordOutcome(client, input);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"recordOutcome: values\")) {\n    logger.warn(\"skipping outcome with no values\", { taskId: input.taskId });\n    return; // empty values are not worth a retry\n  }\n  throw e;\n}","preventionTips":["Skip recordOutcome when the measurement map is empty instead of sending {}.","Build values as object literals, not arrays or class instances.","Unit-test payload construction at the boundary so empty objects never reach the SDK."],"tags":["validation","api","telemetry"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}