{"record":{"id":"40c2ccf16b61d04c","repo":"ianstormtaylor/slate","slug":"got-non-numeric-path-index","errorCode":null,"errorMessage":"Got non-numeric path index","messagePattern":"Got non-numeric path index","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/node.ts","lineNumber":438,"sourceCode":"    const node = Node.getIf(root, path)\n    if (node === undefined) {\n      throw new Error(\n        `Cannot find a descendant at path [${path}] in node: ${Scrubber.stringify(\n          root\n        )}`\n      )\n    }\n    return node\n  },\n\n  getIf(root: Node, path: Path): Node | undefined {\n    let node = root\n\n    for (let i = 0; i < path.length; i++) {\n      const p = path[i]\n\n      if (typeof p !== 'number') {\n        throw new Error('Got non-numeric path index')\n      }\n\n      if (Node.isText(node) || !node.children[p]) {\n        return\n      }\n\n      node = node.children[p]\n    }\n\n    return node\n  },\n\n  has(root: Node, path: Path): boolean {\n    let node = root\n\n    for (let i = 0; i < path.length; i++) {\n      const p = path[i]\n","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/node.ts#L420-L456","documentation":"Node.getIf() iterates over path segments and requires each segment to be a number. A segment was something else (string, undefined, null), which means the path is malformed rather than merely pointing at a missing node. Unlike Node.get, this error cannot be avoided by the usual existence check — it signals a type bug in the caller's path construction.","triggerScenarios":"Passing a path built by spreading a string or mixed array like ['0', 1]; a path containing undefined due to array holes ([ , 0]); JSON-parsed paths where a segment became a string; concatenating a path with a non-numeric value.","commonSituations":"Serializing/deserializing paths as strings and forgetting to convert back to numbers; building paths from untyped external data (URL params, localStorage, server payloads) without validation; TypeScript any-typed path plumbing erasing safety.","solutions":["Validate/normalize the path to numbers before use: path.every(p => typeof p === 'number') or map with Number().","Type paths explicitly as Path (number[]) instead of any/string[] so the compiler catches bad construction.","When ingesting external paths, sanitize: const p = raw.map(Number).filter(n => Number.isInteger(n)).","Fix the source of the path: usually string concatenation ('' + index) or optional chaining producing undefined."],"exampleFix":"// before\nconst path = [String(index), 0] // oops: string segment\nconst node = Node.getIf(editor, path)\n\n// after\nconst path = [index, 0]\nconst node = Node.getIf(editor, path as Path)","handlingStrategy":"type-guard","validationCode":"if (!path.every(p => Number.isInteger(p))) { /* reject/normalize path */ }","typeGuard":"const isPath = (p: unknown): p is Path => Array.isArray(p) && p.every(n => Number.isInteger(n))","tryCatchPattern":null,"preventionTips":["Type paths as Path, never any[].","Convert serialized paths with .map(Number) before use."],"tags":["slate","path","type-error","validation"],"backgroundTag":"slate-invalid-path","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}