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.
This commit is contained in:
Ralph Khreish
2025-12-30 11:45:10 +01:00
parent 31643a4b7c
commit 1f68a113ee

View File

@@ -422,17 +422,17 @@ async function updateTaskById(
} }
// Full update mode: Use structured data directly // Full update mode: Use structured data directly
const updatedTask = { const aiTask = aiServiceResponse.mainResult?.task;
...aiServiceResponse.mainResult.task, if (!aiTask || typeof aiTask !== 'object')
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')
throw new Error('Received invalid task object from AI.'); 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) if (!updatedTask.title || !updatedTask.description)
throw new Error('Updated task missing required fields.'); throw new Error('Updated task missing required fields.');
// Preserve ID if AI changed it // Preserve ID if AI changed it