nexu-io/open-design · error

outputMapping.dataPaths.to array segments must be non-negati

Error message

outputMapping.dataPaths.to array segments must be non-negative integers

What it means

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.

Source

Thrown at apps/daemon/src/live-artifacts/refresh.ts:326

    }
    if (current === undefined) return undefined;
  }
  return current;
}

function makeContainer(nextSegment: string): BoundedJsonObject | BoundedJsonValue[] {
  return /^(?:0|[1-9][0-9]*)$/.test(nextSegment) ? [] : {};
}

function writeMappedValue(root: BoundedJsonObject, path: string, value: BoundedJsonValue): void {
  const segments = parseMappingPath(path, 'outputMapping.dataPaths.to');
  let current: BoundedJsonObject | BoundedJsonValue[] = root;
  for (let index = 0; index < segments.length; index += 1) {
    const segment = segments[index]!;
    const isLast = index === segments.length - 1;
    if (Array.isArray(current)) {
      const arrayIndex = Number(segment);
      if (!Number.isSafeInteger(arrayIndex) || arrayIndex < 0) throw new Error('outputMapping.dataPaths.to array segments must be non-negative integers');
      if (isLast) {
        current[arrayIndex] = value;
        return;
      }
      const next = current[arrayIndex];
      if (!isJsonObject(next) && !Array.isArray(next)) {
        current[arrayIndex] = makeContainer(segments[index + 1]!);
      }
      current = current[arrayIndex] as BoundedJsonObject | BoundedJsonValue[];
      continue;
    }

    if (isLast) {
      current[segment] = value;
      return;
    }
    const next = current[segment];
    if (!isJsonObject(next) && !Array.isArray(next)) {

View on GitHub (pinned to 5be4028344)

Solutions

  1. Ensure dataPaths.to array segments are small, valid non-negative integers (e.g. '0', '1').
  2. Confirm the target container shape matches the path (use object keys, not array indices, when writing into an object).
  3. Keep indices within safe-integer range; avoid computing huge indices dynamically.

Example fix

// before
outputMapping: { dataPaths: [{ from: 'v', to: 'list.99999999999999999999' }] }
// throws `outputMapping.dataPaths.to array segments must be non-negative integers`

// after
outputMapping: { dataPaths: [{ from: 'v', to: 'list.0' }] }
Defensive patterns

Strategy: validation

Validate before calling

function toPathIsValid(p: string): boolean {
  const norm = p.startsWith('$.') ? p.slice(2) : p;
  return norm.split('.').every((seg) => /^(?:0|[1-9][0-9]*)$/.test(seg)
    ? Number.isSafeInteger(Number(seg))
    : /^[A-Za-z_][A-Za-z0-9_-]*$/.test(seg));
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12). Data as JSON: /api/errors/c65f1e19e1c2f0cf. Report an issue: GitHub.