{"record":{"id":"f310809177fc5509","repo":"eyaltoledano/claude-task-master","slug":"core-function-error","errorCode":"CORE_FUNCTION_ERROR","errorMessage":"${error.message}","messagePattern":"\\$\\{error\\.message\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/core/direct-functions/add-dependency.js","lineNumber":106,"sourceCode":"\t\tdisableSilentMode();\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\tmessage: `Successfully added dependency: Task ${taskId} now depends on ${dependencyId}`,\n\t\t\t\ttaskId: taskId,\n\t\t\t\tdependencyId: dependencyId\n\t\t\t}\n\t\t};\n\t} catch (error) {\n\t\t// Make sure to restore normal logging even if there's an error\n\t\tdisableSilentMode();\n\n\t\tlog.error(`Error in addDependencyDirect: ${error.message}`);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tcode: 'CORE_FUNCTION_ERROR',\n\t\t\t\tmessage: error.message\n\t\t\t}\n\t\t};\n\t}\n}\n","sourceCodeStart":88,"sourceCodeEnd":112,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/add-dependency.js#L88-L112","documentation":"This is addDependencyDirect's top-level catch handler. Any error thrown while executing the core addDependency logic — file read/write failures, JSON parse errors of tasks.json, unknown task IDs, or filesystem permission problems — is caught and returned as a structured result with code CORE_FUNCTION_ERROR, carrying the original error's message. disableSilentMode() is restored before returning so logging state isn't left corrupted.","triggerScenarios":"tasksJsonPath points to a nonexistent or unreadable file; tasks.json contains invalid JSON; id or dependsOn references a task that doesn't exist; the tasks.json file is locked or read-only when the core function tries to write; any exception thrown inside core's addDependency().","commonSituations":"Running the MCP server with a different working directory or user than the project owner (permission denied); tasks.json corrupted by a merge conflict; referencing a task ID from another project's file; concurrent writes racing between the CLI and the MCP server.","solutions":["Read result.error.message — it is the underlying core error and usually names the real cause (ENOENT, EACCES, task not found, etc.).","Verify tasksJsonPath points to an existing, valid tasks.json (check with a JSON linter).","Confirm both id and dependsOn exist as tasks in the file before calling.","Check file permissions for the user running the MCP server.","Avoid concurrent modifications: close other Task Master sessions writing to the same tasks.json."],"exampleFix":"// before\nconst res = await addDependencyDirect(args);\nconsole.log(res); // opaque failure\n// after\nconst res = await addDependencyDirect(args);\nif (!res.success) {\n  if (res.error.code === 'CORE_FUNCTION_ERROR') {\n    console.error(`Core addDependency failed: ${res.error.message}`);\n  }\n}\n// and validate the file first:\nJSON.parse(fs.readFileSync(tasksJsonPath, 'utf8'));","handlingStrategy":"try-catch","validationCode":"function preflightDependency(args) {\n  const raw = fs.readFileSync(args.tasksJsonPath, 'utf8');\n  const data = JSON.parse(raw); // throws on corrupted file\n  const ids = new Set(data.tasks.map(t => String(t.id)));\n  if (!ids.has(String(args.id))) throw new Error(`Task ${args.id} not found`);\n  if (!ids.has(String(args.dependsOn))) throw new Error(`Task ${args.dependsOn} not found`);\n  fs.accessSync(args.tasksJsonPath, fs.constants.W_OK); // throws if not writable\n}","typeGuard":"function isCoreFunctionError(result) {\n  return result?.success === false && result?.error?.code === 'CORE_FUNCTION_ERROR' && typeof result.error.message === 'string';\n}","tryCatchPattern":"const result = await addDependencyDirect(args);\nif (isCoreFunctionError(result)) {\n  console.error(`addDependency failed: ${result.error.message}`);\n  // branch on message: 'not found' -> fix IDs; ENOENT/EACCES -> fix path/permissions\n}","preventionTips":["Always check result.success before using the result — these wrappers return errors, they don't throw.","Validate tasks.json is parseable JSON and both IDs exist before calling.","Ensure the MCP server process has write permission on tasks.json.","Avoid running CLI and MCP writes concurrently on the same tasks.json."],"tags":["mcp","error-wrapping","filesystem","core-function"],"backgroundTag":"core-function-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}