{"record":{"id":"a9c64f315ea6c26b","repo":"eyaltoledano/claude-task-master","slug":"warning-could-not-gather-task-context-error-me","errorCode":null,"errorMessage":"Warning: Could not gather task context: ${error.message}","messagePattern":"Warning: Could not gather task context: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"scripts/modules/utils/contextGatherer.js","lineNumber":564,"sourceCode":"\t\t\t\tif (formattedItem && itemInfo) {\n\t\t\t\t\tcontextItems.push(formattedItem);\n\t\t\t\t\tif (includeTokenCounts) {\n\t\t\t\t\t\tbreakdown.push(itemInfo);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (contextItems.length === 0) {\n\t\t\t\treturn { context: null, breakdown: [] };\n\t\t\t}\n\n\t\t\tconst finalContext = this._formatTaskContextSection(contextItems, format);\n\t\t\treturn {\n\t\t\t\tcontext: finalContext,\n\t\t\t\tbreakdown: includeTokenCounts ? breakdown : []\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconsole.warn(`Warning: Could not gather task context: ${error.message}`);\n\t\t\treturn { context: null, breakdown: [] };\n\t\t}\n\t}\n\n\t/**\n\t * Format a task for context inclusion\n\t * @param {Object} task - Task object\n\t * @param {string} format - Output format\n\t * @returns {string} Formatted task context\n\t */\n\t_formatTaskForContext(task, format) {\n\t\tconst sections = [];\n\n\t\tsections.push(`**Task ${task.id}: ${task.title}**`);\n\t\tsections.push(`Description: ${task.description}`);\n\t\tsections.push(`Status: ${task.status || 'pending'}`);\n\t\tsections.push(`Priority: ${task.priority || 'medium'}`);\n","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/utils/contextGatherer.js#L546-L582","documentation":"ContextGatherer._gatherTaskContext collects context items for a task and formats them; on any error it warns with this message and returns {context: null, breakdown: []} so callers degrade gracefully instead of failing. This is a logged message, not a thrown error.","triggerScenarios":"Calling _gatherTaskContext (via taskContextResult) when item gathering or formatting throws — underlying task files unreadable, unexpected task structure (missing fields), or formatter errors on malformed dependency data.","commonSituations":"Gathering context for a task ID that doesn't exist; tasks.json with dangling dependency IDs; schema drift between task data versions; token-counting failures when includeTokenCounts is enabled.","solutions":["Verify the target task ID exists and its dependencies resolve in tasks.json","Repair malformed task/dependency data flagged in the underlying error","Re-run after fixing tasks.json; treat null context as a signal the task data needs attention","Check file read permissions on the task storage"],"exampleFix":"// before\n{ \"id\": 3, \"dependencies\": [99] }  // dangling dep\n// after\n{ \"id\": 3, \"dependencies\": [1] }","handlingStrategy":"fallback","validationCode":"const data = JSON.parse(readFileSync('.taskmaster/tasks/tasks.json', 'utf8'));\nconst task = data.tasks.find(t => t.id === taskId);\nif (!task) console.error(`Task ${taskId} not found — context will be null`);\nconst depIds = (task?.dependencies ?? []).map(d => Number(d));\nconst missing = depIds.filter(id => !data.tasks.some(t => t.id === id));\nif (missing.length) console.error(`Dangling dependencies: ${missing}`);","typeGuard":"function hasGatherableContext(result) {\n  return result !== null && typeof result.context === 'string' && result.context.length > 0;\n}","tryCatchPattern":"const { context } = await gatherer.gatherTaskContext(taskId);\nif (context === null) {\n  console.warn(`No context gathered for task ${taskId} — fix task data and retry`);\n}","preventionTips":["Ensure the target task ID exists before gathering context","Remove or fix dangling dependency IDs in tasks.json","Regenerate context after task schema/version upgrades","Check the console warning text — it contains the underlying error.message"],"tags":["context","tasks","degraded","data-integrity"],"backgroundTag":"task-context-gather-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}