{"record":{"id":"4dacb0ba9cadd7a2","repo":"JuliusBrussee/caveman","slug":"path-must-be-a-plain-object-array-or-primitiv","errorCode":null,"errorMessage":"${path} must be a plain object, array, or primitive","messagePattern":"(.+?) must be a plain object, array, or primitive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mastra/src/index.ts","lineNumber":748,"sourceCode":" * plain object, array, string, finite number, boolean, or null — a Date, a Map,\n * or a class instance would serialize into something the caller did not mean,\n * and the record's digest is its identity.\n */\nexport function stableStringify(value: unknown, path = \"value\"): string {\n  if (value === null) return \"null\";\n  switch (typeof value) {\n    case \"string\":\n      return JSON.stringify(value);\n    case \"boolean\":\n      return value ? \"true\" : \"false\";\n    case \"number\":\n      if (!Number.isFinite(value)) throw new Error(`${path} must be a finite number`);\n      return JSON.stringify(value);\n    case \"object\": {\n      if (Array.isArray(value)) {\n        return `[${value.map((item, i) => stableStringify(item, `${path}[${i}]`)).join(\",\")}]`;\n      }\n      if (!isPlainObject(value)) throw new Error(`${path} must be a plain object, array, or primitive`);\n      const entries = Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n      return `{${entries\n        .map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item, `${path}.${key}`)}`)\n        .join(\",\")}}`;\n    }\n    default:\n      throw new Error(`${path} must be JSON data (got ${typeof value})`);\n  }\n}\n\n// ---------------------------------------------------------------------------\n// 5. Deep links\n// ---------------------------------------------------------------------------\n\n/**\n * Mastra Studio's documented default address. The dev server listens on 4111\n * (or `PORT`): https://mastra.ai/docs/studio/overview\n */","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/packages/mastra/src/index.ts#L730-L766","documentation":"Guard inside stableStringify: the value at the given path is an object but is neither an array nor a plain object (e.g. a Date, Map, Set, or class instance). Such values would serialize differently than the caller intends and corrupt the record digest.","triggerScenarios":"Thrown at packages/mastra/src/index.ts:748 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert Dates to ISO strings and Maps/Sets to plain objects/arrays before stringifying","Rebuild the payload using only plain objects, arrays, and primitives","Add a pre-pass that calls toJSON() or a custom encoder on non-plain values"],"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"}