From 2ee356dfdfc22bc83f6768b2232fe20971fa8637 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:14:54 +0000 Subject: [PATCH] fix(#5): preserve original payload indexes in duplicate validation errors --- src/lib/shared/networkSchemaCore.mjs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib/shared/networkSchemaCore.mjs b/src/lib/shared/networkSchemaCore.mjs index add90d0..1ef7cce 100644 --- a/src/lib/shared/networkSchemaCore.mjs +++ b/src/lib/shared/networkSchemaCore.mjs @@ -363,27 +363,31 @@ export function validateNetworkData(value) { } const machines = []; + const machineEntries = []; for (const [machineIndex, machineValue] of (Array.isArray(machinesRaw) ? machinesRaw : []).entries()) { const machine = normalizeMachine(issues, `$.machines[${machineIndex}]`, machineValue); if (machine) { machines.push(machine); + machineEntries.push({ machine, originalIndex: machineIndex }); } } const devices = []; + const deviceEntries = []; for (const [deviceIndex, deviceValue] of (Array.isArray(devicesRaw) ? devicesRaw : []).entries()) { const device = normalizeDevice(issues, `$.devices[${deviceIndex}]`, deviceValue); if (device) { devices.push(device); + deviceEntries.push({ device, originalIndex: deviceIndex }); } } const seenMachineNames = new Set(); - for (const [index, machine] of machines.entries()) { + for (const { machine, originalIndex } of machineEntries) { const key = machine.machineName.toLowerCase(); if (seenMachineNames.has(key)) { issues.push({ - path: `$.machines[${index}].machineName`, + path: `$.machines[${originalIndex}].machineName`, message: `duplicate machine name "${machine.machineName}"` }); } @@ -391,21 +395,21 @@ export function validateNetworkData(value) { } const seenDeviceNames = new Set(); - for (const [index, device] of devices.entries()) { + for (const { device, originalIndex } of deviceEntries) { const key = device.name.toLowerCase(); if (seenDeviceNames.has(key)) { issues.push({ - path: `$.devices[${index}].name`, + path: `$.devices[${originalIndex}].name`, message: `duplicate device name "${device.name}"` }); } seenDeviceNames.add(key); } - for (const [index, machine] of machines.entries()) { + for (const { machine, originalIndex } of machineEntries) { if (seenDeviceNames.has(machine.machineName.toLowerCase())) { issues.push({ - path: `$.machines[${index}].machineName`, + path: `$.machines[${originalIndex}].machineName`, message: `name "${machine.machineName}" collides with a device name` }); }