{"record":{"id":"710892c7e39860f3","repo":"mastra-ai/mastra","slug":"child-object-must-be-a-an-array-of-relatednodeinfo","errorCode":null,"errorMessage":"Child object must be a an array of RelatedNodeInfo objects","messagePattern":"Child object must be a an array of RelatedNodeInfo objects","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/document/schema/node.ts","lineNumber":73,"sourceCode":"\n    return relationship;\n  }\n\n  get parentNode(): RelatedNodeInfo<T> | undefined {\n    const relationship = this.relationships[NodeRelationship.PARENT];\n\n    if (Array.isArray(relationship)) {\n      throw new Error('Parent object must be a single RelatedNodeInfo object');\n    }\n\n    return relationship;\n  }\n\n  get childNodes(): RelatedNodeInfo<T>[] | undefined {\n    const relationship = this.relationships[NodeRelationship.CHILD];\n\n    if (!Array.isArray(relationship)) {\n      throw new Error('Child object must be a an array of RelatedNodeInfo objects');\n    }\n\n    return relationship;\n  }\n\n  abstract generateHash(): string;\n}\n\n/**\n * TextNode is the default node type for text.\n */\nexport class TextNode<T extends Metadata = Metadata> extends BaseNode<T> {\n  text: string;\n\n  startCharIdx?: number;\n  endCharIdx?: number;\n  metadataSeparator: string;\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/document/schema/node.ts#L55-L91","documentation":"The BaseNode.childNodes getter reads the CHILD relationship, which must be an array of RelatedNodeInfo objects. If the value is missing or a single object (not an array), the getter throws because children are inherently a collection.","triggerScenarios":"Accessing node.childNodes when relationships[NodeRelationship.CHILD] is undefined or was set to a single RelatedNodeInfo object instead of an array.","commonSituations":"Assigning one child without wrapping it in an array (symmetry mistake with source/prev/next/parent), or partial deserialization that drops the CHILD entry.","solutions":["Assign an array even for one child: relationships[NodeRelationship.CHILD] = [childInfo].","Guard undefined: only read childNodes after relationships are populated (e.g. by a splitter or fromJSON).","Normalize deserialized data so CHILD is always an array (possibly empty)."],"exampleFix":"// before\nnode.relationships[NodeRelationship.CHILD] = childInfo;\n// after\nnode.relationships[NodeRelationship.CHILD] = [childInfo];","handlingStrategy":"type-guard","validationCode":"const rel = node.relationships[NodeRelationship.CHILD];\nconst children = Array.isArray(rel) ? rel : rel !== undefined ? [rel] : [];","typeGuard":"const isRelatedNodeInfoArray = (v: unknown): v is RelatedNodeInfo[] =>\n  Array.isArray(v) && v.every(x => x !== null && typeof x === 'object' && 'nodeId' in x);","tryCatchPattern":"let children: RelatedNodeInfo[] = [];\ntry {\n  children = node.childNodes;\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Child object must be')) {\n    const rel = node.relationships[NodeRelationship.CHILD];\n    children = rel !== undefined && !Array.isArray(rel) ? [rel] : [];\n  } else throw e;\n}","preventionTips":["Always wrap child assignments in an array, even for a single child.","Initialize CHILD as [] when creating nodes you'll link later.","Normalize deserialized maps so CHILD is always an array."],"tags":["data-structure","rag","relationships"],"backgroundTag":"invalid-relationship-shape","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}