{"record":{"id":"855066ded4e56a93","repo":"pydantic/monty","slug":"classinstance-attr-value-missing","errorCode":null,"errorMessage":"ClassInstance attr value missing","messagePattern":"ClassInstance attr value missing","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/worker/value.ts","lineNumber":191,"sourceCode":" * strings). Validation messages mirror napi's so both transports fail\n * malformed markers alike.\n */\nfunction pushClassInstance(object: Record<string, unknown>, nodes: ValueNode[]): ValueNode {\n  if (typeof object.type !== 'object' || object.type === null) {\n    throw new TypeError(\n      `Object property 'type' type mismatch. Expect value to be Object, but received ${jsType(object.type)}`,\n    )\n  }\n  if (!Array.isArray(object.attrs)) {\n    throw new TypeError(\n      `Object property 'attrs' type mismatch. Expect value to be Array, but received ${jsType(object.attrs)}`,\n    )\n  }\n  const pairs: [unknown, unknown][] = []\n  for (const pair of object.attrs as unknown[]) {\n    if (!Array.isArray(pair)) throw new TypeError('ClassInstance attrs entries must be [name, value] pairs')\n    if (typeof pair[0] !== 'string') throw new TypeError('ClassInstance attr name must be a string')\n    if (!(1 in pair)) throw new TypeError('ClassInstance attr value missing')\n    pairs.push([pair[0], pair[1]])\n  }\n  const classTypeNode = pushClassType(object.type as Record<string, unknown>, nodes)\n  const classTypeIndex = nodes.length\n  nodes.push({ tag: 'class-type', val: classTypeNode })\n  return {\n    tag: 'class-instance',\n    val: {\n      classType: classTypeIndex,\n      instanceId: uuidString(object.instanceId, 'ClassInstance instanceId'),\n      attrs: pushPairs(pairs, nodes),\n    },\n  }\n}\n\n/** Builds a class-type node from the plain `classType` marker object,\n *  appending its eager attr nodes to the arena. */\nfunction pushClassType(","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/worker/value.ts#L173-L209","documentation":"Validation guard in the wasm-worker `pushClassInstance` converter: fires when a `ClassInstance` marker's `attrs` entry has no second element (the attribute value). Every `[name, value]` pair must carry a value node for the instance attribute; a truncated pair means the host built the marker incorrectly and is rejected with a TypeError.","triggerScenarios":"attrs pairs like ['x'] or ['x', ] built by truncating arrays; destructuring failures leaving undefined intentionally distinguished from a real value; sparse arrays where index 1 is a hole (note: explicit undefined passes, a missing slot does not).","commonSituations":"Slicing pair arrays incorrectly; serializers that drop trailing empty values from arrays.","solutions":["Always supply both elements in each pair, even if the value is null or undefined: ['x', undefined] passes","Pre-check pairs with p.length >= 2 || (1 in p)","Fix the producing code so values are never dropped from pairs"],"exampleFix":"// before\nattrs: [['x']]\n// after\nattrs: [['x', 1]] // or ['x', null] if the value is intentionally absent","handlingStrategy":"validation","validationCode":"const pairsComplete = (attrs: unknown[]): boolean => attrs.every(a => Array.isArray(a) && 1 in a)","typeGuard":"const hasValue = (p: unknown): p is [string, unknown] => Array.isArray(p) && 1 in p","tryCatchPattern":"try {\n  return pushClassInstance(object, nodes)\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'ClassInstance attr value missing') {\n    // supply an explicit value (null/undefined) for the offending pair and retry\n  }\n  throw e\n}","preventionTips":["Never truncate pair arrays; always emit both elements","Remember explicit undefined passes but a missing slot (hole) does not — write ['x', undefined], not ['x']","Check serializer settings so trailing empty values are preserved"],"tags":["typescript","validation","class-instance","array"],"backgroundTag":"missing-required-argument","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}