{"record":{"id":"c2eb57818a1df6a6","repo":"eyaltoledano/claude-task-master","slug":"failed-to-load-tasks-error-message","errorCode":null,"errorMessage":"Failed to load tasks: ${error.message}","messagePattern":"Failed to load tasks: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/tm-core/src/modules/storage/adapters/file-storage/file-storage.ts","lineNumber":153,"sourceCode":"\t\t\t\tif (options.status) {\n\t\t\t\t\ttasks = tasks.filter((task) => task.status === options.status);\n\t\t\t\t}\n\n\t\t\t\t// Exclude subtasks if specified\n\t\t\t\tif (options.excludeSubtasks) {\n\t\t\t\t\ttasks = tasks.map((task) => ({\n\t\t\t\t\t\t...task,\n\t\t\t\t\t\tsubtasks: []\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn await this.enrichTasksWithComplexity(tasks, resolvedTag);\n\t\t} catch (error: any) {\n\t\t\tif (error.code === 'ENOENT') {\n\t\t\t\treturn []; // File doesn't exist, return empty array\n\t\t\t}\n\t\t\tthrow new Error(`Failed to load tasks: ${error.message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Load a single task by ID from the tasks.json file\n\t * Handles both regular tasks and subtasks (with dotted notation like \"1.2\")\n\t */\n\tasync loadTask(taskId: string, tag?: string): Promise<Task | null> {\n\t\tconst tasks = await this.loadTasks(tag);\n\n\t\t// Check if this is a subtask (contains a dot)\n\t\tif (taskId.includes('.')) {\n\t\t\tconst [parentId, subtaskId] = taskId.split('.');\n\t\t\tconst parentTask = tasks.find((t) => String(t.id) === parentId);\n\n\t\t\tif (!parentTask || !parentTask.subtasks) {\n\t\t\t\treturn null;\n\t\t\t}","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/storage/adapters/file-storage/file-storage.ts#L135-L171","documentation":"loadTasks() reads the single tasks.json file for a tag and enriches tasks with complexity data. ENOENT is treated as 'no tasks yet' (empty array); any other error — JSON corruption, permissions, enrichment failures — is wrapped and rethrown as 'Failed to load tasks'.","triggerScenarios":"tasks.json exists but contains invalid JSON, EACCES/EACCES-style permission denial, tasks.json is a directory, or enrichTasksWithComplexity throws while merging complexity report data into the loaded tasks.","commonSituations":"A partially written tasks.json from a crashed process or interrupted save, a complexity report referencing malformed data, repo cloned without read permissions, or a symlink pointing at a nonexistent/unreadable target.","solutions":["Inspect error.message in the thrown error for the root cause (parse vs permission)","Validate and repair tasks.json JSON syntax or restore it from version control","Fix permissions: chmod u+r .taskmaster/tasks.json","If the file should not exist yet, delete the corrupt file so ENOENT handling returns an empty task list"],"exampleFix":"// before\nconst tasks = await tmCore.tasks.get(); // throws 'Failed to load tasks: Unexpected token...'\n// after: guard the environment first\nimport { existsSync, readFileSync } from 'fs';\nconst p = '.taskmaster/tasks.json';\nif (existsSync(p)) JSON.parse(readFileSync(p, 'utf8')); // fail fast with a clear parse error\nconst tasks = await tmCore.tasks.get();","handlingStrategy":"try-catch","validationCode":"import { existsSync } from 'fs';\nfunction tasksFileLooksValid(path = '.taskmaster/tasks.json') {\n  if (!existsSync(path)) return true; // ENOENT => empty list is fine\n  try { const d = JSON.parse(readFileSync(path, 'utf8')); return typeof d === 'object' && d !== null; }\n  catch { return false; }\n}","typeGuard":"function isLoadTasksError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('Failed to load tasks:');\n}","tryCatchPattern":"try {\n  const tasks = await storage.loadTasks(tag);\n} catch (e) {\n  if (isLoadTasksError(e)) {\n    // surface the inner cause: e.message.split('Failed to load tasks: ')[1]\n    // offer repair/restore UX or restore from backup before retrying\n  } else throw e;\n}","preventionTips":["Use atomic writes (write temp file + rename) when modifying tasks.json yourself","Validate JSON after manual edits with a linter","Back up tasks.json before bulk operations","Check file permissions after cloning repos across users"],"tags":["storage","file-io","json-parse"],"backgroundTag":"file-read-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}