eyaltoledano/claude-task-master · error · MoveTaskError

TASK_NOT_FOUND

TASK_NOT_FOUND

Error message

Source task with ID ${sourceTaskId} not found

What it means

This MoveTaskError with code TASK_NOT_FOUND is thrown by moveTaskToSubtask when the source task ID to be converted into a subtask does not exist in the tasks array. moveTaskToSubtask looks up tasks.findIndex(t => t.id === sourceTaskId) and throws immediately if the index is -1. It prevents proceeding with a move that would otherwise silently do nothing.

Source

Thrown at scripts/modules/task-manager/move-task.js:387

	return {
		message: `Converted subtask ${sourceId} to task ${destinationId}`,
		movedItem: newTask
	};
}

function moveTaskToSubtask(tasks, sourceId, destinationId) {
	// Parse IDs
	const sourceTaskId = parseInt(sourceId, 10);
	const [destParentId, destSubtaskId] = destinationId
		.split('.')
		.map((id) => parseInt(id, 10));

	// Find source task and destination parent
	const sourceTaskIndex = tasks.findIndex((t) => t.id === sourceTaskId);
	const destParentTask = tasks.find((t) => t.id === destParentId);

	if (sourceTaskIndex === -1) {
		throw new MoveTaskError(
			MOVE_ERROR_CODES.TASK_NOT_FOUND,
			`Source task with ID ${sourceTaskId} not found`
		);
	}
	if (!destParentTask) {
		throw new MoveTaskError(
			MOVE_ERROR_CODES.PARENT_TASK_NOT_FOUND,
			`Destination parent task with ID ${destParentId} not found`
		);
	}

	const sourceTask = tasks[sourceTaskIndex];

	// Initialize subtasks array if it doesn't exist (based on commit fixes)
	if (!destParentTask.subtasks) {
		destParentTask.subtasks = [];
	}

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Verify the source ID exists: `tasks.some(t => t.id === sourceTaskId)` before calling moveTask.
  2. List tasks to confirm the correct ID, then retry with the right one.
  3. Check you are operating on the correct tag context; the task may exist under a different tag.
  4. If the ID is a subtask (e.g. 5.2), ensure the move path used supports subtask sources rather than task-to-subtask.
  5. Correct stale scripts/configs that reference deleted task IDs.

Example fix

// before
moveTask(tasksPath, '12', '3.1'); // task 12 doesn't exist
// after
const tasks = readJSON(tasksPath);
if (tasks.some(t => t.id === 12)) {
  moveTask(tasksPath, '12', '3.1');
} else {
  console.error('Task 12 not found; check `task-master list`.');
}
Defensive patterns

Strategy: validation

Validate before calling

const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
const pool = [...(data.master?.tasks ?? [])];
if (!pool.some(t => t.id === Number(sourceTaskId))) {
  throw new Error(`Source task ${sourceTaskId} not found in current tag.`);
}

Type guard

function taskExists(tasks, id) {
  return tasks.findIndex(t => t.id === Number(id)) !== -1;
}

Try / catch

try {
  await moveTask(tasksPath, sourceId, '3.1');
} catch (e) {
  if (e.code === 'TASK_NOT_FOUND') {
    console.error(`No task ${sourceId}; run the list command to get valid IDs.`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling moveTask with a plain numeric source ID (not a subtask form) and a subtask destination (parentId.subtaskId), where the source ID has been deleted, was never created, or is mistyped (e.g. '12' when only tasks 1-10 exist).

Common situations: Typo in task ID on the CLI; task was deleted in another session/tag context so the local file no longer has it; hardcoded IDs in automation scripts after the task list changed; confusing subtask IDs (5.2) with top-level IDs.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/a688bdf4c0827429. Report an issue: GitHub.