{"record":{"id":"00910fb35b11f929","repo":"ianstormtaylor/slate","slug":"got-non-numeric-path-index-00910f","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/path.ts","lineNumber":203,"sourceCode":"\n    if (reverse) {\n      paths = paths.slice(1)\n    } else {\n      paths = paths.slice(0, -1)\n    }\n\n    return paths\n  },\n\n  common(path: Path, another: Path): Path {\n    const common: Path = []\n\n    for (let i = 0; i < path.length && i < another.length; i++) {\n      const av = path[i]\n      const bv = another[i]\n\n      if (typeof av !== 'number' || typeof bv !== 'number') {\n        throw new Error('Got non-numeric path index')\n      }\n\n      if (av !== bv) {\n        break\n      }\n\n      common.push(av)\n    }\n\n    return common\n  },\n\n  compare(path: Path, another: Path): -1 | 0 | 1 {\n    const min = Math.min(path.length, another.length)\n\n    for (let i = 0; i < min; i++) {\n      if (path[i] < another[i]) return -1\n      if (path[i] > another[i]) return 1","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/path.ts#L185-L221","documentation":"Path.common() computes the shared prefix of two paths by pairwise comparing segments; every segment must be a number. One of the paths contained a non-numeric segment (string, undefined, etc.), so the comparison cannot proceed.","triggerScenarios":"Calling Path.common(pathA, pathB) where either array contains a string index, undefined, or null; paths assembled from serialized strings or unvalidated external data; one path being undefined itself and index access yielding undefined.","commonSituations":"Persisting/loading paths (localStorage, server, URL) as strings like '0.1' and splitting without converting to numbers; mixing path types after JSON round-trips; a variable typed any shadowing a real Path.","solutions":["Coerce external paths: const p = raw.split('.').map(Number) before use.","Type both arguments as Path and construct paths only via Path APIs or numeric array operations.","Add a runtime guard: path.every(n => Number.isInteger(n)) before calling Path.common.","Fix upstream bugs where an index is computed with string ops or where optional access yields undefined."],"exampleFix":"// before\nconst common = Path.common(pathA.split('.'), pathB) // string segments!\n\n// after\nconst common = Path.common(pathA.split('.').map(Number) as Path, pathB)","handlingStrategy":"type-guard","validationCode":"const ok = [a, b].every(p => p.every(n => Number.isInteger(n)))\nif (!ok) { /* reject */ }","typeGuard":"const isPath = (p: unknown): p is Path => Array.isArray(p) && p.every(n => Number.isInteger(n))","tryCatchPattern":null,"preventionTips":["Coerce split-string paths with .map(Number).","Keep both operands typed as Path."],"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"}