{"record":{"id":"b6e19eac0436043f","repo":"eyaltoledano/claude-task-master","slug":"task-with-id-taskid-not-found-in-tag-tag","errorCode":null,"errorMessage":"Task with ID ${taskId} not found in tag '${tag}'","messagePattern":"Task with ID (.+?) not found in tag '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/remove-task.js","lineNumber":105,"sourceCode":"\t\t\t\t\tconst removedSubtask = {\n\t\t\t\t\t\t...parentTask.subtasks[subtaskIndex],\n\t\t\t\t\t\tparentTaskId: parentTaskId\n\t\t\t\t\t};\n\t\t\t\t\tresults.removedTasks.push(removedSubtask);\n\n\t\t\t\t\t// Remove the subtask from the parent\n\t\t\t\t\tparentTask.subtasks.splice(subtaskIndex, 1);\n\n\t\t\t\t\tresults.messages.push(\n\t\t\t\t\t\t`Successfully removed subtask ${taskId} from tag '${tag}'`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Handle main task removal\n\t\t\t\telse {\n\t\t\t\t\tconst taskIdNum = parseInt(taskId, 10);\n\t\t\t\t\tconst taskIndex = tasks.findIndex((t) => t.id === taskIdNum);\n\t\t\t\t\tif (taskIndex === -1) {\n\t\t\t\t\t\tthrow new Error(`Task with ID ${taskId} not found in tag '${tag}'`);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Store the task info before removal\n\t\t\t\t\tconst removedTask = tasks[taskIndex];\n\t\t\t\t\tresults.removedTasks.push(removedTask);\n\t\t\t\t\ttasksToDeleteFiles.push(taskIdNum); // Add to list for file deletion\n\n\t\t\t\t\t// Remove the task from the main array\n\t\t\t\t\ttasks.splice(taskIndex, 1);\n\n\t\t\t\t\tresults.messages.push(\n\t\t\t\t\t\t`Successfully removed task ${taskId} from tag '${tag}'`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (innerError) {\n\t\t\t\t// Catch errors specific to processing *this* ID\n\t\t\t\tconst errorMsg = `Error processing ID ${taskId}: ${innerError.message}`;\n\t\t\t\tresults.errors.push(errorMsg);","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/remove-task.js#L87-L123","documentation":"removeTask() throws this when a main task ID cannot be found in the parsed task list for the current tag. After parsing the ID to an integer it uses findIndex over data.tasks; a -1 result means no task with that numeric id exists under the active tag. This is a data lookup failure, not a crash: the ID is either wrong, belongs to a different tag, or the task file is missing that entry.","triggerScenarios":"Calling removeTask(taskId) (or tasks.remove) with an ID that does not exist in the tasks.json for the active tag, e.g. removeTask('5') when only tasks 1-4 exist, passing a non-numeric string that parseInt maps to a wrong number (parseInt('5abc') === 5), or removing while a tag other than the one containing the task is active.","commonSituations":"Stale IDs after regenerating task lists, working in a multi-tag workspace where the task exists in 'feature-x' but not 'master', typos in scripts/automation calling removeTask, or tasks.json edited manually and an entry deleted.","solutions":["List tasks in the active tag (task-master list) and confirm the exact ID before calling removeTask.","Check which tag is active (task-master tags) and either switch tags or pass context.tag pointing at the tag containing the task.","If the ID contains non-numeric characters, strip them first so parseInt resolves the intended number.","Wrap the call in try/catch and surface a friendly 'task not found' message to the user instead of a stack trace."],"exampleFix":"// before\nawait removeTask('5', { tag: 'master' });\n// after\nconst tasks = readJSON(tasksPath, projectRoot, 'master').tasks;\nif (tasks.some((t) => t.id === 5)) {\n  await removeTask('5', { tag: 'master' });\n} else {\n  console.log('Task 5 does not exist in master; check `task-master list`');\n}","handlingStrategy":"validation","validationCode":"const tasks = readJSON(tasksPath, projectRoot, tag)?.tasks || [];\nconst id = parseInt(taskId, 10);\nif (!tasks.some((t) => t.id === id)) {\n  throw new Error(`Task ${id} not found in tag '${tag}' — run 'task-master list' first`);\n}\nawait removeTask(taskId, { tag });","typeGuard":"function taskExistsIn(tasks, taskId) {\n  const id = parseInt(taskId, 10);\n  return Number.isInteger(id) && tasks.some((t) => t.id === id);\n}","tryCatchPattern":"try {\n  await removeTask(taskId, { tag });\n} catch (err) {\n  if (err.message.includes('not found in tag')) {\n    console.error(`Task ${taskId} does not exist in tag '${tag}'. Available: ${listIds()}`);\n  } else throw err;\n}","preventionTips":["Always list tasks in the active tag before removing by ID","Check the active tag with 'task-master tags' in multi-tag workspaces","Sanitize ID strings so parseInt resolves the intended number","Cache task IDs only for a single script run; re-read tasks.json each time"],"tags":["task-not-found","lookup","tag-scoping"],"backgroundTag":"resource-not-found","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}