Skip to content

Commit 1d8d723

Browse files
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.
1 parent 2f101ca commit 1d8d723

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

scripts/modules/task-manager/update-task-by-id.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,17 @@ async function updateTaskById(
422422
}
423423

424424
// Full update mode: Use structured data directly
425+
const aiTask = aiServiceResponse.mainResult?.task;
426+
if (!aiTask || typeof aiTask !== 'object')
427+
throw new Error('Received invalid task object from AI.');
428+
425429
const updatedTask = {
426-
...aiServiceResponse.mainResult.task,
427-
dependencies: aiServiceResponse.mainResult.task.dependencies ?? [],
428-
priority: aiServiceResponse.mainResult.task.priority ?? null,
429-
details: aiServiceResponse.mainResult.task.details ?? null,
430-
testStrategy: aiServiceResponse.mainResult.task.testStrategy ?? null
430+
...aiTask,
431+
dependencies: aiTask.dependencies ?? [],
432+
priority: aiTask.priority ?? null,
433+
details: aiTask.details ?? null,
434+
testStrategy: aiTask.testStrategy ?? null
431435
};
432-
433-
// --- Task Validation/Correction (Keep existing logic) ---
434-
if (!updatedTask || typeof updatedTask !== 'object')
435-
throw new Error('Received invalid task object from AI.');
436436
if (!updatedTask.title || !updatedTask.description)
437437
throw new Error('Updated task missing required fields.');
438438
// Preserve ID if AI changed it

0 commit comments

Comments
 (0)