{"record":{"id":"d3ee3c83578cf3d1","repo":"eyaltoledano/claude-task-master","slug":"invalid-tasks-file-d3ee3c","errorCode":"INVALID_TASKS_FILE","errorMessage":"No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}","messagePattern":"No valid tasks found in (.+?)\\. readJSON returned: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/core/direct-functions/expand-task.js","lineNumber":115,"sourceCode":"\t\tlog.info(\n\t\t\t`[expandTaskDirect] Expanding task ${taskId} into ${numSubtasks || 'default'} subtasks. Research: ${useResearch}, Force: ${forceFlag}`\n\t\t);\n\n\t\t// Read tasks data\n\t\tlog.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`);\n\t\tconst data = readJSON(tasksPath, projectRoot);\n\t\tlog.info(\n\t\t\t`[expandTaskDirect] Result of readJSON: ${data ? 'Data read successfully' : 'readJSON returned null or undefined'}`\n\t\t);\n\n\t\tif (!data || !data.tasks) {\n\t\t\tlog.error(\n\t\t\t\t`[expandTaskDirect] readJSON failed or returned invalid data for path: ${tasksPath}`\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: 'INVALID_TASKS_FILE',\n\t\t\t\t\tmessage: `No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}`\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t// Find the specific task\n\t\tlog.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`);\n\t\tconst task = data.tasks.find((t) => t.id === taskId);\n\t\tlog.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`);\n\n\t\tif (!task) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: 'TASK_NOT_FOUND',\n\t\t\t\t\tmessage: `Task with ID ${taskId} not found`\n\t\t\t\t}\n\t\t\t};","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/expand-task.js#L97-L133","documentation":"expandTaskDirect loads the tasks file via readJSON and expects an object containing a valid tasks array. If readJSON fails or returns data without usable tasks, it returns this INVALID_TASKS_FILE error, embedding the path and the raw parsed data for diagnosis.","triggerScenarios":"tasks.json missing entirely, containing malformed JSON, holding an empty tasks array, or having the wrong shape (e.g. top-level array instead of {tasks:[...]}); wrong tasksJsonPath pointing to another file.","commonSituations":"Fresh projects where tasks.json was never generated (no parse-prd run); manual edits corrupting the file; an empty scaffold file created by an editor; pointing at a legacy or foreign schema file.","solutions":["Confirm tasksJsonPath points to the real .taskmaster/tasks.json and open it to check contents.","Fix JSON syntax or restore from backup; validate with a JSON parser.","Regenerate tasks if empty: run the PRD parsing flow (e.g. 'task-master parse-prd') to populate tasks.","Ensure the file shape is { \"tasks\": [ ... ] } with at least the target task present."],"exampleFix":"// before\n// tasks.json: { }  -> INVALID_TASKS_FILE\n// after\n// tasks.json: { \"tasks\": [ { \"id\": 1, \"title\": \"...\", \"status\": \"pending\", ... } ] }\nawait expandTaskDirect({ tasksJsonPath, id: '1' });","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction tasksFileIsValid(p) {\n  try {\n    const data = JSON.parse(fs.readFileSync(p, 'utf8'));\n    return Array.isArray(data?.tasks) && data.tasks.length > 0;\n  } catch { return false; }\n}\nif (!tasksFileIsValid(tasksJsonPath)) {\n  throw new Error(`${tasksJsonPath} is missing, malformed, or has no tasks`);\n}","typeGuard":"function isTasksData(d) {\n  return d !== null && typeof d === 'object' &&\n    Array.isArray(d.tasks) && d.tasks.length > 0;\n}","tryCatchPattern":"const res = await expandTaskDirect(args);\nif (!res.success && res.error?.code === 'INVALID_TASKS_FILE') {\n  // inspect res.error.message for the path and raw data, then repair/regenerate the file\n}","preventionTips":["Never hand-edit tasks.json without re-validating JSON afterwards.","Generate tasks via parse-prd before enabling expansion tools in new projects.","Keep schema { tasks: [...] }; migrate legacy formats explicitly.","Back up tasks.json before bulk operations so corruption is recoverable."],"tags":["mcp-server","json","file-format","tasks-file"],"backgroundTag":"invalid-tasks-file","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}