{"record":{"id":"cd564dacfcf1f37f","repo":"eyaltoledano/claude-task-master","slug":"invalid-tasks-file-cd564d","errorCode":"INVALID_TASKS_FILE","errorMessage":"No valid tasks found in ${tasksJsonPath}${tag ? ` for tag '${tag}'` : ''}","messagePattern":"No valid tasks found in (.+?)(.+?)'` : ''\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/core/direct-functions/remove-task.js","lineNumber":70,"sourceCode":"\t\t\t\t\tmessage: 'Task ID is required'\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t// Split task IDs if comma-separated\n\t\tconst taskIdArray = id.split(',').map((taskId) => taskId.trim());\n\n\t\tlog.info(\n\t\t\t`Removing ${taskIdArray.length} task(s) with ID(s): ${taskIdArray.join(', ')} from ${tasksJsonPath}${tag ? ` in tag '${tag}'` : ''}`\n\t\t);\n\n\t\t// Validate all task IDs exist before proceeding\n\t\tconst data = readJSON(tasksJsonPath, projectRoot, tag);\n\t\tif (!data || !data.tasks) {\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 ${tasksJsonPath}${tag ? ` for tag '${tag}'` : ''}`\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tconst invalidTasks = taskIdArray.filter(\n\t\t\t(taskId) => !taskExists(data.tasks, taskId)\n\t\t);\n\n\t\tif (invalidTasks.length > 0) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: 'INVALID_TASK_ID',\n\t\t\t\t\tmessage: `The following tasks were not found${tag ? ` in tag '${tag}'` : ''}: ${invalidTasks.join(', ')}`\n\t\t\t\t}\n\t\t\t};\n\t\t}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/remove-task.js#L52-L88","documentation":"removeTaskDirect reads the tasks file with readJSON before removing tasks. If the file cannot be read, parses to nothing, or contains no `tasks` array (e.g. under the given tag), the function returns INVALID_TASKS_FILE because there is no task data to validate ids against.","triggerScenarios":"tasksJsonPath points to a missing or empty file, the JSON root has no `tasks` array, the file is corrupt/partially written, or the `tag` filter targets a tag that has no tasks array in .taskmaster/state or the tasks file.","commonSituations":"Running remove_task before any tasks exist (no init/generate yet); wrong projectRoot so the path resolves to a non-existent file; switching tags where the target tag was never created; manual edits that dropped the tasks key; interrupted writes leaving truncated JSON.","solutions":["Verify the tasks.json file exists at tasksJsonPath and contains a top-level `tasks` array (run task-master list to confirm)","Check the `projectRoot` and `tag` arguments resolve to the right file/tag; create the tag first if needed (tag tool or task-master tags --create)","Re-initialize or regenerate the task data (task-master init / parse-prd) if the file is missing or corrupt","Restore tasks.json from backup or version control if a manual edit removed the tasks array"],"exampleFix":"// before\nawait client.callTool('remove_task', { id: '5', tasksJsonPath: './tasks.json' });\n\n// after\nawait client.callTool('remove_task', { id: '5', projectRoot: '/correct/project', tasksJsonPath: '/correct/project/.taskmaster/tasks/tasks.json' });","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'fs';\nfunction tasksFileLooksValid(tasksJsonPath, tag) {\n  try {\n    const data = JSON.parse(readFileSync(tasksJsonPath, 'utf8'));\n    if (!Array.isArray(data.tasks)) return false;\n    if (tag && data.tags && !data.tags[tag]) return false;\n    return true;\n  } catch {\n    return false;\n  }\n}","typeGuard":"function isValidTasksData(data) {\n  return typeof data === 'object' && data !== null &&\n    Array.isArray(data.tasks) && data.tasks.length >= 0;\n}","tryCatchPattern":"try {\n  const res = await client.callTool('remove_task', { id, projectRoot });\n  if (res.error?.code === 'INVALID_TASKS_FILE') {\n    console.error(`Tasks file missing or empty at ${res.error.message} — run task-master init or fix projectRoot/tag`);\n  }\n} catch (e) {\n  console.error('remove_task failed:', e.message);\n}","preventionTips":["Confirm tasks.json exists and has a tasks array before any mutating call","Pass the correct projectRoot so the server resolves the real .taskmaster workspace","Create/select the tag before operating on tag-scoped data","Commit or back up tasks.json so corrupt/lost state is recoverable"],"tags":["mcp","file","tasks-json"],"backgroundTag":"tasks-file-invalid","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}