{"record":{"id":"c65f1e19e1c2f0cf","repo":"nexu-io/open-design","slug":"outputmapping-datapaths-to-array-segments-must-be","errorCode":null,"errorMessage":"outputMapping.dataPaths.to array segments must be non-negative integers","messagePattern":"outputMapping\\.dataPaths\\.to array segments must be non-negative integers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/daemon/src/live-artifacts/refresh.ts","lineNumber":326,"sourceCode":"    }\n    if (current === undefined) return undefined;\n  }\n  return current;\n}\n\nfunction makeContainer(nextSegment: string): BoundedJsonObject | BoundedJsonValue[] {\n  return /^(?:0|[1-9][0-9]*)$/.test(nextSegment) ? [] : {};\n}\n\nfunction writeMappedValue(root: BoundedJsonObject, path: string, value: BoundedJsonValue): void {\n  const segments = parseMappingPath(path, 'outputMapping.dataPaths.to');\n  let current: BoundedJsonObject | BoundedJsonValue[] = root;\n  for (let index = 0; index < segments.length; index += 1) {\n    const segment = segments[index]!;\n    const isLast = index === segments.length - 1;\n    if (Array.isArray(current)) {\n      const arrayIndex = Number(segment);\n      if (!Number.isSafeInteger(arrayIndex) || arrayIndex < 0) throw new Error('outputMapping.dataPaths.to array segments must be non-negative integers');\n      if (isLast) {\n        current[arrayIndex] = value;\n        return;\n      }\n      const next = current[arrayIndex];\n      if (!isJsonObject(next) && !Array.isArray(next)) {\n        current[arrayIndex] = makeContainer(segments[index + 1]!);\n      }\n      current = current[arrayIndex] as BoundedJsonObject | BoundedJsonValue[];\n      continue;\n    }\n\n    if (isLast) {\n      current[segment] = value;\n      return;\n    }\n    const next = current[segment];\n    if (!isJsonObject(next) && !Array.isArray(next)) {","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/live-artifacts/refresh.ts#L308-L344","documentation":"writeMappedValue (refresh.ts:318-348) writes a value into the mapped output along a dataPaths.to path. When the current node is an array, the segment must be a non-negative integer index; otherwise this throws. Note parseMappingPath already enforces the segment regex, so in practice this guards against the rare case where a numeric-looking segment is somehow rejected by Number()/isSafeInteger.","triggerScenarios":"A dataPaths.to path targets an array index, but the segment fails the non-negative-integer check at write time (e.g. a segment that passed the regex but is out of safe-integer range, or a code path where the container became an array unexpectedly).","commonSituations":"A very large numeric index that exceeds Number.MAX_SAFE_INTEGER; an output container that is an array where the mapping expected an object; an edge case in path construction.","solutions":["Ensure dataPaths.to array segments are small, valid non-negative integers (e.g. '0', '1').","Confirm the target container shape matches the path (use object keys, not array indices, when writing into an object).","Keep indices within safe-integer range; avoid computing huge indices dynamically."],"exampleFix":"// before\noutputMapping: { dataPaths: [{ from: 'v', to: 'list.99999999999999999999' }] }\n// throws `outputMapping.dataPaths.to array segments must be non-negative integers`\n\n// after\noutputMapping: { dataPaths: [{ from: 'v', to: 'list.0' }] }","handlingStrategy":"validation","validationCode":"function toPathIsValid(p: string): boolean {\n  const norm = p.startsWith('$.') ? p.slice(2) : p;\n  return norm.split('.').every((seg) => /^(?:0|[1-9][0-9]*)$/.test(seg)\n    ? Number.isSafeInteger(Number(seg))\n    : /^[A-Za-z_][A-Za-z0-9_-]*$/.test(seg));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep to-path array indices as small non-negative integers within safe-integer range.","Match the target container shape: use object keys for objects, numeric indices for arrays.","Validate to-paths with a unit test that mirrors writeMappedValue's traversal."],"tags":["live-artifacts","output-mapping","json-path","array"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}