{"record":{"id":"4e45a37a3068f8f5","repo":"eyaltoledano/claude-task-master","slug":"invalid-tasks-data-in-taskspath-4e45a3","errorCode":null,"errorMessage":"Invalid tasks data in ${tasksPath}","messagePattern":"Invalid tasks data in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/expand-task.js","lineNumber":99,"sourceCode":"\t\t\tprojectRoot,\n\t\t\ttag,\n\t\t\tisMCP,\n\t\t\toutputFormat,\n\t\t\treport\n\t\t});\n\n\t\t// If remote handled it, return the result\n\t\tif (remoteResult) {\n\t\t\treturn remoteResult;\n\t\t}\n\t\t// Otherwise fall through to file-based logic below\n\t\t// --- End BRIDGE ---\n\n\t\t// --- Task Loading/Filtering (Unchanged) ---\n\t\tlogger.info(`Reading tasks from ${tasksPath}`);\n\t\tconst data = readJSON(tasksPath, projectRoot, tag);\n\t\tif (!data || !data.tasks)\n\t\t\tthrow new Error(`Invalid tasks data in ${tasksPath}`);\n\t\tconst taskIndex = data.tasks.findIndex(\n\t\t\t(t) => t.id === parseInt(taskId, 10)\n\t\t);\n\t\tif (taskIndex === -1) throw new Error(`Task ${taskId} not found`);\n\t\tconst task = data.tasks[taskIndex];\n\t\tlogger.info(\n\t\t\t`Expanding task ${taskId}: ${task.title}${useResearch ? ' with research' : ''}`\n\t\t);\n\t\t// --- End Task Loading/Filtering ---\n\n\t\t// --- Handle Force Flag: Clear existing subtasks if force=true ---\n\t\tif (force && Array.isArray(task.subtasks) && task.subtasks.length > 0) {\n\t\t\tlogger.info(\n\t\t\t\t`Force flag set. Clearing existing ${task.subtasks.length} subtasks for task ${taskId}.`\n\t\t\t);\n\t\t\ttask.subtasks = []; // Clear existing subtasks\n\t\t}\n\t\t// --- End Force Flag Handling ---","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/expand-task.js#L81-L117","documentation":"expandTask() loads the tasks file and, before doing anything else, validates that readJSON returned an object with a tasks array. If the file is missing, unparseable, or lacks tasks, it throws this error naming the path, mirroring the same check as expand-all-tasks.","triggerScenarios":"Calling expandTask(taskId) when the tasks file at tasksPath cannot be read or parsed (readJSON → null), or its top-level JSON has no tasks field.","commonSituations":"Corrupted tasks.json after a failed write or merge conflict; running from a different project root so the resolved path points to a nonexistent file; wrong active tag resolving to an empty/absent per-tag file.","solutions":["Open the tasks file at the path in the message and fix any JSON syntax errors.","Ensure you are running in the correct project root / tag so the correct tasks file is resolved.","If the file is unrecoverable, regenerate it (parse-prd or init) and re-run expansion."],"exampleFix":"// before\n$ cat .taskmaster/tasks/tasks.json\n{ \"tasks\": [ ... \"truncated invalid json\"\n// after\n$ task-master parse-prd prd.txt   # regenerate valid tasks.json, then retry expand","handlingStrategy":"type-guard","validationCode":"const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));\nif (!Array.isArray(data.tasks)) throw new Error(`${tasksPath} has no tasks array`);","typeGuard":"function isTasksData(v) {\n  return !!v && typeof v === 'object' && Array.isArray(v.tasks);\n}","tryCatchPattern":"try {\n  await expandTask(taskId, context);\n} catch (err) {\n  if (err.message.startsWith('Invalid tasks data in')) {\n    console.error(`Repair or regenerate ${tasksPath}, then retry.`);\n  } else throw err;\n}","preventionTips":["Keep tasks.json valid JSON — lint after edits and merge conflict resolution.","Verify file existence before invoking expandTask in scripts.","Use the correct project root and tag when resolving tasksPath."],"tags":["tasks-file","file-parsing","validation"],"backgroundTag":"invalid-tasks-json","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}