{"record":{"id":"9c8117b57f9b99d3","repo":"eyaltoledano/claude-task-master","slug":"invalid-or-missing-tasks-file-at-taskspath","errorCode":null,"errorMessage":"Invalid or missing tasks file at ${tasksPath}","messagePattern":"Invalid or missing tasks file at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/add-subtask.js","lineNumber":31,"sourceCode":" * @param {string} context.tag - Tag for the task\n * @returns {Object} The newly created or converted subtask\n */\nasync function addSubtask(\n\ttasksPath,\n\tparentId,\n\texistingTaskId = null,\n\tnewSubtaskData = null,\n\tgenerateFiles = false,\n\tcontext = {}\n) {\n\tconst { projectRoot, tag } = context;\n\ttry {\n\t\tlog('info', `Adding subtask to parent task ${parentId}...`);\n\n\t\t// Read the existing tasks with proper context\n\t\tconst data = readJSON(tasksPath, projectRoot, tag);\n\t\tif (!data || !data.tasks) {\n\t\t\tthrow new Error(`Invalid or missing tasks file at ${tasksPath}`);\n\t\t}\n\n\t\t// Convert parent ID to number\n\t\tconst parentIdNum = parseInt(parentId, 10);\n\n\t\t// Find the parent task\n\t\tconst parentTask = data.tasks.find((t) => t.id === parentIdNum);\n\t\tif (!parentTask) {\n\t\t\tthrow new Error(`Parent task with ID ${parentIdNum} not found`);\n\t\t}\n\n\t\t// Initialize subtasks array if it doesn't exist\n\t\tif (!parentTask.subtasks) {\n\t\t\tparentTask.subtasks = [];\n\t\t}\n\n\t\tlet newSubtask;\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/add-subtask.js#L13-L49","documentation":"addSubtask throws this when readJSON on the tasks file returns nothing usable — either the file does not exist, is unparseable, or the parsed object has no 'tasks' array. addSubtask needs the full task list to locate the parent task and write back changes, so it fails fast before mutating anything.","triggerScenarios":"Calling addSubtask with a tasksPath that points to a non-existent, empty, corrupted, or schema-invalid JSON file, or one whose top-level object lacks 'tasks'.","commonSituations":"Running commands in the wrong project directory (no .taskmaster/tasks.json), a failed earlier write truncating the file, or pointing at a different tag file that was never initialized.","solutions":["Verify tasksPath points to an existing, valid tasks JSON file (e.g. .taskmaster/tasks.json).","If the file is missing, initialize it (run task-master init or create the file with {\"tasks\":[]}).","Validate the JSON parses (e.g. node -e \"require(path)\") and contains a 'tasks' array.","Re-run the add-subtask command from the correct project root."],"exampleFix":"// before (missing file)\naddSubtask('tasks/missing.json', '1', { title: 'Sub' });\n// after\n// create .taskmaster/tasks.json with {\"tasks\":[...]} first\naddSubtask('.taskmaster/tasks.json', '1', { title: 'Sub' });","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertValidTasksFile(tasksPath) {\n  if (!fs.existsSync(tasksPath)) throw new Error(`${tasksPath} does not exist`);\n  const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));\n  if (!data || !Array.isArray(data.tasks)) throw new Error(`${tasksPath} has no tasks array`);\n  return data;\n}","typeGuard":"function isTasksData(d) {\n  return typeof d === 'object' && d !== null && Array.isArray(d.tasks);\n}","tryCatchPattern":"try {\n  await addSubtask(tasksPath, parentId, opts);\n} catch (err) {\n  if (err.message.startsWith('Invalid or missing tasks file')) {\n    // initialize or repair the tasks file, then retry once\n  } else throw err;\n}","preventionTips":["Run task-master commands from the project root where .taskmaster lives","Check file existence and JSON validity after crashes or interrupted writes","Keep the tasks file in version control to detect corruption","Confirm the correct tag file path before scripted operations"],"tags":["filesystem","tasks-file","json","missing-file"],"backgroundTag":"invalid-tasks-file","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}