{"record":{"id":"92002c3759933f5b","repo":"eyaltoledano/claude-task-master","slug":"could-not-read-tasks-file-at-taskspath","errorCode":null,"errorMessage":"Could not read tasks file at ${tasksPath}","messagePattern":"Could not read tasks file at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/remove-task.js","lineNumber":38,"sourceCode":"\t\terrors: [],\n\t\tremovedTasks: []\n\t};\n\tconst taskIdsToRemove = taskIds\n\t\t.split(',')\n\t\t.map((id) => id.trim())\n\t\t.filter(Boolean); // Remove empty strings if any\n\n\tif (taskIdsToRemove.length === 0) {\n\t\tresults.success = false;\n\t\tresults.errors.push('No valid task IDs provided.');\n\t\treturn results;\n\t}\n\n\ttry {\n\t\t// Read the tasks file ONCE before the loop, preserving the full tagged structure\n\t\tconst rawData = readJSON(tasksPath, projectRoot, tag); // Read raw data\n\t\tif (!rawData) {\n\t\t\tthrow new Error(`Could not read tasks file at ${tasksPath}`);\n\t\t}\n\n\t\t// Use the full tagged data if available, otherwise use the data as is\n\t\tconst fullTaggedData = rawData._rawTaggedData || rawData;\n\n\t\tif (!fullTaggedData[tag] || !fullTaggedData[tag].tasks) {\n\t\t\tthrow new Error(`Tag '${tag}' not found or has no tasks.`);\n\t\t}\n\n\t\tconst tasks = fullTaggedData[tag].tasks; // Work with tasks from the correct tag\n\n\t\tconst tasksToDeleteFiles = []; // Collect IDs of main tasks whose files should be deleted\n\n\t\tfor (const taskId of taskIdsToRemove) {\n\t\t\t// Check if the task ID exists *before* attempting removal\n\t\t\tif (!taskExists(tasks, taskId)) {\n\t\t\t\tconst errorMsg = `Task with ID ${taskId} in tag '${tag}' not found or already removed.`;\n\t\t\t\tresults.errors.push(errorMsg);","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/remove-task.js#L20-L56","documentation":"removeTask reads the tasks file once via readJSON before processing IDs. If readJSON returns a falsy value — file missing, empty, or unparseable — this error is thrown before any task removal happens.","triggerScenarios":"Calling removeTask with a tasksPath pointing to a nonexistent, empty, or corrupt tasks.json, or a path with wrong permissions preventing a valid read.","commonSituations":"Running remove-task before init/parse-prd ever created tasks.json, wrong --project-root or working directory, file corrupted by a failed write or manual edit.","solutions":["Create or restore tasks.json: run init/parse-prd or restore from git.","Confirm the file exists and is valid JSON at the resolved path (jq . tasks.json).","Run from the correct project root or pass the correct project-root option.","Check file permissions so the process can read the file."],"exampleFix":"// before\n.task-master/tasks.json  // empty file after failed write\n// after\n{\n  \"master\": { \"tasks\": [ ... ] }\n} // restored via `git checkout -- .task-master/tasks.json`","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nif (!fs.existsSync(tasksPath) || fs.statSync(tasksPath).size === 0) {\n  throw new Error(`tasks.json missing or empty at ${tasksPath}; run task-master init or restore it`);\n}\nJSON.parse(fs.readFileSync(tasksPath, 'utf8')); // throws on corrupt JSON","typeGuard":"function isReadableTasksFile(p) {\n  try {\n    return fs.existsSync(p) && JSON.parse(fs.readFileSync(p, 'utf8')) != null;\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  await tmCore.tasks.removeTask(tasksPath, taskIds);\n} catch (err) {\n  if (err.message.startsWith('Could not read tasks file')) {\n    console.error(`Cannot read ${tasksPath}. Check existence, permissions, and JSON validity.`);\n  } else throw err;\n}","preventionTips":["Verify tasks.json exists and parses before scripted removals.","Restore tasks.json from git if a write was interrupted.","Run from the project root or pass an explicit project root.","Check read permissions for the running user."],"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"}