Browse Source

docs: Set Fields fails loudly rather than quietly dropping data

fszontagh 1 tháng trước cách đây
mục cha
commit
93509bce52
1 tập tin đã thay đổi với 18 bổ sung và 5 xóa
  1. 18 5
      docs/superpowers/plans/2026-08-04-tier-1-nodes.md

+ 18 - 5
docs/superpowers/plans/2026-08-04-tier-1-nodes.md

@@ -1029,8 +1029,13 @@ function setByPath(target, path, value) {
     let cursor = target;
     for (let i = 0; i < keys.length - 1; i++) {
         const key = keys[i];
-        if (cursor[key] === null || typeof cursor[key] !== 'object') {
+        const existing = cursor[key];
+        if (existing === undefined) {
             cursor[key] = {};
+        } else if (existing === null || typeof existing !== 'object' || Array.isArray(existing)) {
+            const held = Array.isArray(existing) ? 'an array' : existing === null ? 'null' : 'a ' + typeof existing;
+            throw new Error('Cannot set "' + path + '": "' + keys.slice(0, i + 1).join('.') +
+                '" already holds ' + held + ', which would be overwritten');
         }
         cursor = cursor[key];
     }
@@ -1063,9 +1068,12 @@ async function execute(config, input, context) {
     if (mode === 'only-set') {
         output = {};
     } else {
-        output = source !== null && typeof source === 'object' && !Array.isArray(source)
-            ? JSON.parse(JSON.stringify(source))
-            : {};
+        if (source === null || typeof source !== 'object' || Array.isArray(source)) {
+            const got = Array.isArray(source) ? 'an array' : source === null ? 'null' : 'a ' + typeof source;
+            throw new Error('Set Fields: keep-all needs an object input, got ' + got +
+                '. Use only-set mode, or Split Out first.');
+        }
+        output = JSON.parse(JSON.stringify(source));
     }
 
     for (const field of fields) {
@@ -1846,8 +1854,13 @@ function setByPath(target, path, value) {
     let cursor = target;
     for (let i = 0; i < keys.length - 1; i++) {
         const key = keys[i];
-        if (cursor[key] === null || typeof cursor[key] !== 'object') {
+        const existing = cursor[key];
+        if (existing === undefined) {
             cursor[key] = {};
+        } else if (existing === null || typeof existing !== 'object' || Array.isArray(existing)) {
+            const held = Array.isArray(existing) ? 'an array' : existing === null ? 'null' : 'a ' + typeof existing;
+            throw new Error('Cannot set "' + path + '": "' + keys.slice(0, i + 1).join('.') +
+                '" already holds ' + held + ', which would be overwritten');
         }
         cursor = cursor[key];
     }