{"record":{"id":"3917866db951d499","repo":"eyaltoledano/claude-task-master","slug":"invalid-or-missing-tasks-file-at-taskspath-391786","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/remove-subtask.js","lineNumber":28,"sourceCode":" * @param {string} [context.projectRoot] - Project root path\n * @param {string} [context.tag] - Tag for the task\n * @returns {Object|null} The removed subtask if convertToTask is true, otherwise null\n */\nasync function removeSubtask(\n\ttasksPath,\n\tsubtaskId,\n\tconvertToTask = false,\n\tgenerateFiles = false,\n\tcontext = {}\n) {\n\tconst { projectRoot, tag } = context;\n\ttry {\n\t\tlog('info', `Removing subtask ${subtaskId}...`);\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// Parse the subtask ID (format: \"parentId.subtaskId\")\n\t\tif (!subtaskId.includes('.')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid subtask ID format: ${subtaskId}. Expected format: \"parentId.subtaskId\"`\n\t\t\t);\n\t\t}\n\n\t\tconst [parentIdStr, subtaskIdStr] = subtaskId.split('.');\n\t\tconst parentId = parseInt(parentIdStr, 10);\n\t\tconst subtaskIdNum = parseInt(subtaskIdStr, 10);\n\n\t\t// Find the parent task\n\t\tconst parentTask = data.tasks.find((t) => t.id === parentId);\n\t\tif (!parentTask) {\n\t\t\tthrow new Error(`Parent task with ID ${parentId} not found`);\n\t\t}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/remove-subtask.js#L10-L46","documentation":"removeSubtask throws this when readJSON on the tasks.json path returns null/undefined or an object without a tasks array. It means the task data file is missing, unreadable, corrupted JSON, or has an unexpected structure.","triggerScenarios":"Calling removeSubtask with a tasksPath that does not exist, points to an empty/corrupt file, or a file whose parsed JSON lacks the top-level tasks field (including missing tag data).","commonSituations":"Running remove-subtask before ever initializing tasks (no tasks.json), wrong project root/tag resolving to a nonexistent file path, manual edits that broke JSON structure, or pointing at the wrong tasks file path.","solutions":["Run 'task-master init' or create/repair the tasks.json file in the project's .task-master directory.","Confirm you are in the correct project root and using the right --tag.","Validate the JSON file parses (e.g. jq . tasks.json) and contains a top-level \"tasks\" array.","If the file was deleted, regenerate tasks via parse-prd or restore from version control."],"exampleFix":"// before\n{ \"tasks\": [] } // file missing or renamed to tasks.backup.json\n// after\n{\n  \"master\": { \"tasks\": [ ... ] }\n} // valid tagged tasks.json restored","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nif (!fs.existsSync(tasksPath)) throw new Error(`tasks.json not found at ${tasksPath}; run task-master init or parse-prd first`);\nconst raw = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));\nconst tasks = raw[tag]?.tasks ?? raw.tasks;\nif (!Array.isArray(tasks)) throw new Error('tasks.json has no tasks array for the active tag');","typeGuard":"function isValidTasksData(d) {\n  return d != null && typeof d === 'object' &&\n    Array.isArray((d as any).tasks);\n}","tryCatchPattern":"try {\n  await tmCore.tasks.removeSubtask(tasksPath, subtaskId);\n} catch (err) {\n  if (err.message.startsWith('Invalid or missing tasks file')) {\n    console.error('tasks.json missing or corrupt. Re-init or restore it before removing subtasks.');\n  } else throw err;\n}","preventionTips":["Always initialize the project (task-master init / parse-prd) before task mutations.","Validate tasks.json with a JSON parser after manual edits.","Commit tasks.json (or back it up) so it can be restored.","Run commands from the correct project root.","Keep tooling and scripts updated so file paths resolve consistently."],"tags":["filesystem","tasks-json","validation"],"backgroundTag":"invalid-tasks-file","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}