{"record":{"id":"b439b630d650aa07","repo":"pydantic/monty","slug":"classinstance-marker-instanceid-must-be-a-uuid-string","errorCode":null,"errorMessage":"ClassInstance marker instanceId must be a uuid string","messagePattern":"ClassInstance marker instanceId must be a uuid string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/classInstance.ts","lineNumber":653,"sourceCode":" */\nfunction classTypeObject(wrapper: ClassType, store: InstanceStore, depth: number): Record<string, unknown> {\n  const attrs = wrapper\n    .getEagerAttrs()\n    .map(([name, value]): [string, unknown] => [name, prepareInner(value, store, depth + 1)])\n  return {\n    name: wrapper.getName(),\n    id: wrapper.id,\n    hostDefined: true,\n    // JS has no dataclasses; host-wrapped objects always cross as plain classes\n    isDataclass: false,\n    attrs,\n  }\n}\n\n/** Maps an inbound `ClassInstance` marker to the original instance or a proxy. */\nfunction markerToInstance(marker: Record<string, unknown>, store: InstanceStore): unknown {\n  if (typeof marker.instanceId !== 'string') {\n    throw new TypeError('ClassInstance marker instanceId must be a uuid string')\n  }\n  const wrapper = store.get(marker.instanceId)\n  if (wrapper !== undefined) {\n    return wrapper.instance\n  }\n  const attrs: Array<[string, unknown]> = []\n  if (Array.isArray(marker.attrs)) {\n    for (const pair of marker.attrs as unknown[]) {\n      if (Array.isArray(pair) && typeof pair[0] === 'string') {\n        attrs.push([pair[0], restore(pair[1], store)])\n      }\n    }\n  }\n  const classType = (marker.type ?? {}) as Record<string, unknown>\n  return new MontyClassProxy(classType, marker.instanceId, attrs)\n}\n\n/** Maps an inbound `Type` marker to the registered host class, else leaves","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/classInstance.ts#L635-L671","documentation":"When restoring an inbound ClassInstance marker, markerToInstance requires the marker's instanceId to be a string (a uuid) so it can look the instance up in the store. A marker whose instanceId is missing or of any other type throws this TypeError — normally a sign of a corrupted or hand-crafted marker.","triggerScenarios":"A marker-shaped object reaching restore with instanceId undefined, a number, or a non-string value — e.g. restored wire data that was truncated, altered, or built by hand.","commonSituations":"Manually constructing marker objects instead of using the library's prepare output; partial deserialization dropping the instanceId field; JSON schemas where instanceId collided with another key.","solutions":["Ensure markers always come from the library's own prepare/restore pipeline, not hand-built objects","Validate that serialized snapshots contain a string instanceId before restoring","If a legitimately unknown instanceId is expected, wrap fresh host objects in ClassInstance(...) so a new id is assigned"],"exampleFix":"// before\nrestore({ type: 'ClassInstance', instanceId: 42 });\n// after\nrestore({ type: 'ClassInstance', instanceId: '3f2504e0-4f89-11d3-9a0c-0305e82c3301' });","handlingStrategy":"validation","validationCode":"function validateMarker(marker) {\n  if (marker?.type === 'ClassInstance' && typeof marker.instanceId !== 'string') {\n    throw new Error('corrupt ClassInstance marker: instanceId must be a string uuid');\n  }\n}","typeGuard":"function hasValidInstanceId(marker) {\n  return typeof marker === 'object' && marker !== null && typeof marker.instanceId === 'string';\n}","tryCatchPattern":"try {\n  const obj = restore(marker);\n} catch (e) {\n  if (e instanceof TypeError && e.message.includes('instanceId must be a uuid string')) {\n    throw new Error('marker data is corrupt or hand-built; recreate it via the library API');\n  }\n  throw e;\n}","preventionTips":["Only restore markers produced by the library itself","Validate serialized snapshots for a string instanceId before restoring","Version and checksum persisted marker data so truncation is detected"],"tags":["typescript","class-instance","uuid","validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}