{"record":{"id":"6a5194c5a0a96bae","repo":"eyaltoledano/claude-task-master","slug":"task-with-id-existingtaskidnum-not-found","errorCode":null,"errorMessage":"Task with ID ${existingTaskIdNum} not found","messagePattern":"Task with ID (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/add-subtask.js","lineNumber":59,"sourceCode":"\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\n\t\t// Case 1: Convert an existing task to a subtask\n\t\tif (existingTaskId !== null) {\n\t\t\tconst existingTaskIdNum = parseInt(existingTaskId, 10);\n\n\t\t\t// Find the existing task\n\t\t\tconst existingTaskIndex = data.tasks.findIndex(\n\t\t\t\t(t) => t.id === existingTaskIdNum\n\t\t\t);\n\t\t\tif (existingTaskIndex === -1) {\n\t\t\t\tthrow new Error(`Task with ID ${existingTaskIdNum} not found`);\n\t\t\t}\n\n\t\t\tconst existingTask = data.tasks[existingTaskIndex];\n\n\t\t\t// Check if task is already a subtask\n\t\t\tif (existingTask.parentTaskId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Task ${existingTaskIdNum} is already a subtask of task ${existingTask.parentTaskId}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Check for circular dependency\n\t\t\tif (existingTaskIdNum === parentIdNum) {\n\t\t\t\tthrow new Error(`Cannot make a task a subtask of itself`);\n\t\t\t}\n\n\t\t\t// Check if parent task is a subtask of the task we're converting\n\t\t\t// This would create a circular dependency","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/add-subtask.js#L41-L77","documentation":"When converting an existing task into a subtask, addSubtask looks up existingTaskId in the tasks array; this error is thrown when the given ID does not match any top-level task. The conversion cannot proceed without the source task record.","triggerScenarios":"Calling addSubtask(parentId, existingTaskId) where existingTaskId refers to a nonexistent, deleted, or out-of-range task ID.","commonSituations":"Passing a subtask ID ('1.2') instead of a top-level ID, stale IDs after renumbering or regeneration, or referencing tasks in a different tag.","solutions":["List current tasks to confirm the ID of the task you want to convert.","Pass a valid top-level task ID as existingTaskId.","If the task is actually a subtask already, reference its top-level ID or handle it via update-subtask instead.","Verify you are in the correct tag/context."],"exampleFix":"// before\nawait addSubtask('1', '4.2'); // '4.2' is not a top-level task\n// after\nawait addSubtask('1', '5'); // top-level task 5 exists","handlingStrategy":"type-guard","validationCode":"const data = readJSON(tasksPath, projectRoot, tag);\nconst idNum = parseInt(existingTaskId, 10);\nif (!data.tasks.some(t => t.id === idNum)) {\n  throw new Error(`Cannot convert: task ${idNum} does not exist`);\n}","typeGuard":"function isTopLevelTask(data, id) {\n  const n = Number(id);\n  return data?.tasks?.some(t => t.id === n && !t.parentTaskId && !String(t.id).includes('.'));\n}","tryCatchPattern":"try {\n  await addSubtask(tasksPath, parentId, existingTaskId);\n} catch (err) {\n  if (/Task with ID .* not found/.test(err.message)) {\n    console.error('Refresh task list and retry with a valid top-level ID');\n  } else throw err;\n}","preventionTips":["Confirm IDs against a fresh 'task-master list' before conversions","Use only top-level task IDs for existingTaskId","Handle ID renumbering after regenerate operations","Check you are in the right tag context"],"tags":["tasks","not-found","id-lookup"],"backgroundTag":"task-not-found","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}