From 1f68a113eea6a095334cf6f82d1952c85c1e0725 Mon Sep 17 00:00:00 2001 From: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Date: Tue, 30 Dec 2025 11:45:10 +0100 Subject: [PATCH] fix: validate AI task response before spreading object Move validation check before object spread to properly catch null/malformed task responses. Previously crashed with "Cannot read properties of null" instead of the intended "Received invalid task object from AI" error. --- .../modules/task-manager/update-task-by-id.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/modules/task-manager/update-task-by-id.js b/scripts/modules/task-manager/update-task-by-id.js index b4616603..4049c268 100644 --- a/scripts/modules/task-manager/update-task-by-id.js +++ b/scripts/modules/task-manager/update-task-by-id.js @@ -422,17 +422,17 @@ async function updateTaskById( } // Full update mode: Use structured data directly - const updatedTask = { - ...aiServiceResponse.mainResult.task, - dependencies: aiServiceResponse.mainResult.task.dependencies ?? [], - priority: aiServiceResponse.mainResult.task.priority ?? null, - details: aiServiceResponse.mainResult.task.details ?? null, - testStrategy: aiServiceResponse.mainResult.task.testStrategy ?? null - }; - - // --- Task Validation/Correction (Keep existing logic) --- - if (!updatedTask || typeof updatedTask !== 'object') + const aiTask = aiServiceResponse.mainResult?.task; + if (!aiTask || typeof aiTask !== 'object') throw new Error('Received invalid task object from AI.'); + + const updatedTask = { + ...aiTask, + dependencies: aiTask.dependencies ?? [], + priority: aiTask.priority ?? null, + details: aiTask.details ?? null, + testStrategy: aiTask.testStrategy ?? null + }; if (!updatedTask.title || !updatedTask.description) throw new Error('Updated task missing required fields.'); // Preserve ID if AI changed it