{"record":{"id":"48083bfc7b2469af","repo":"eyaltoledano/claude-task-master","slug":"warning-could-not-load-tasks-for-contextgatherer","errorCode":null,"errorMessage":"Warning: Could not load tasks for ContextGatherer: ${error.message}","messagePattern":"Warning: Could not load tasks for ContextGatherer: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"scripts/modules/utils/contextGatherer.js","lineNumber":42,"sourceCode":"\tconstructor(projectRoot, tag) {\n\t\tthis.projectRoot = projectRoot;\n\t\tthis.tasksPath = path.join(\n\t\t\tprojectRoot,\n\t\t\t'.taskmaster',\n\t\t\t'tasks',\n\t\t\t'tasks.json'\n\t\t);\n\t\tthis.tag = tag;\n\t\tthis.allTasks = this._loadAllTasks();\n\t}\n\n\t_loadAllTasks() {\n\t\ttry {\n\t\t\tconst data = readJSON(this.tasksPath, this.projectRoot, this.tag);\n\t\t\tconst tasks = data?.tasks || [];\n\t\t\treturn tasks;\n\t\t} catch (error) {\n\t\t\tconsole.warn(\n\t\t\t\t`Warning: Could not load tasks for ContextGatherer: ${error.message}`\n\t\t\t);\n\t\t\treturn [];\n\t\t}\n\t}\n\n\t/**\n\t * Count tokens in a text string using gpt-tokens\n\t * @param {string} text - Text to count tokens for\n\t * @returns {number} Token count\n\t */\n\tcountTokens(text) {\n\t\tif (!text || typeof text !== 'string') {\n\t\t\treturn 0;\n\t\t}\n\t\ttry {\n\t\t\treturn encode(text).length;\n\t\t} catch (error) {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/utils/contextGatherer.js#L24-L60","documentation":"ContextGatherer._loadAllTasks reads the tasks file via readJSON and returns [] with this warning if reading or parsing fails. The gatherer then operates with no tasks, so context gathering yields empty results rather than crashing the host command.","triggerScenarios":"Constructing a ContextGatherer when readJSON(tasksPath, projectRoot, tag) throws — tasks.json missing, invalid JSON, wrong --tag referenced, or unreadable path.","commonSituations":"Running context-dependent commands before task-master init; corrupted tasks.json after a crash; passing a tag name that has no data; wrong project root cwd.","solutions":["Run `task-master init` or create the tasks file if it's missing","Validate/repair JSON syntax in .taskmaster/tasks/tasks.json","Confirm the tag exists (task-master tags) or omit the tag option","Re-run from the actual project root"],"exampleFix":"// before\n{ \"tasks\": [ { \"id\": 1, \"title\": , } ] }\n// after\n{ \"tasks\": [ { \"id\": 1, \"title\": \"Valid entry\" } ] }","handlingStrategy":"fallback","validationCode":"import { existsSync } from 'fs';\nconst tasksPath = '.taskmaster/tasks/tasks.json';\nif (!existsSync(tasksPath)) {\n  console.error('tasks.json missing — run task-master init before using ContextGatherer');\n} else {\n  try { JSON.parse(readFileSync(tasksPath, 'utf8')); } catch { console.error('tasks.json is not valid JSON'); }\n}","typeGuard":"function isLoadableTasksFile(data) {\n  return data !== null && typeof data === 'object' && Array.isArray(data.tasks);\n}","tryCatchPattern":"const gatherer = new ContextGatherer(projectRoot, tag);\nconst tasks = gatherer._loadAllTasks();\nif (tasks.length === 0) {\n  console.warn('ContextGatherer loaded 0 tasks — check for the load warning above');\n}","preventionTips":["Initialize the project (task-master init) before context-dependent commands","Validate tasks.json after crashes or manual edits","Confirm the tag exists with `task-master tags`","Run commands from the project root, not a subdirectory with a different root"],"tags":["filesystem","json-parse","context","tasks"],"backgroundTag":"tasks-file-unreadable","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}