{"record":{"id":"eaab65e76701368d","repo":"eyaltoledano/claude-task-master","slug":"core-function-error-eaab65","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-subtask.js","lineNumber":168,"sourceCode":"\t\t\tdisableSilentMode();\n\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: {\n\t\t\t\t\tmessage: `New subtask ${parentId}.${result.id} successfully created`,\n\t\t\t\t\tsubtask: result\n\t\t\t\t}\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 addSubtaskDirect: ${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":150,"sourceCodeEnd":174,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/add-subtask.js#L150-L174","documentation":"This is addSubtaskDirect's top-level catch handler. Exceptions raised by the core addSubtask logic — missing parent task, nonexistent taskId, invalid tasks.json, or write failures — are caught and returned as a structured CORE_FUNCTION_ERROR result carrying the original message, with disableSilentMode() restoring logging state first.","triggerScenarios":"Parent id does not exist in tasks.json; taskId references a task that cannot be found; tasks.json is malformed JSON or unreadable; the write-back fails (read-only file, disk full, permission denied); any throw inside core's addSubtask().","commonSituations":"Stale task IDs after tasks.json was regenerated; tasks.json corrupted by merge conflicts; the MCP server running as a user without write access to the project; concurrent CLI/MCP sessions racing on the same file.","solutions":["Inspect result.error.message for the underlying cause (task not found, ENOENT, EACCES, JSON parse error).","Verify both the parent id and the optional taskId exist in tasks.json.","Validate that tasksJsonPath points to well-formed JSON before retrying.","Fix filesystem permissions for the MCP server process.","Retry after resolving the cause; the wrapper never throws, so always check result.success."],"exampleFix":"// before\nconst res = await addSubtaskDirect(args); // throws nothing, may fail silently\n// after\nconst res = await addSubtaskDirect(args);\nif (!res.success && res.error.code === 'CORE_FUNCTION_ERROR') {\n  console.error(`addSubtask failed: ${res.error.message}`);\n  process.exitCode = 1;\n}","handlingStrategy":"try-catch","validationCode":"function preflightSubtask(args) {\n  const data = JSON.parse(fs.readFileSync(args.tasksJsonPath, 'utf8'));\n  const ids = new Set(data.tasks.map(t => String(t.id)));\n  if (!ids.has(String(args.id))) throw new Error(`Parent task ${args.id} not found`);\n  if (args.taskId && !ids.has(String(args.taskId))) throw new Error(`Task ${args.taskId} not found`);\n  fs.accessSync(args.tasksJsonPath, fs.constants.W_OK);\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 addSubtaskDirect(args);\nif (isCoreFunctionError(result)) {\n  console.error(`addSubtask failed: ${result.error.message}`);\n  // 'not found' -> fix IDs; ENOENT/EACCES/parse errors -> fix file path/permissions/content\n}","preventionTips":["Always inspect result.success — the wrapper returns errors instead of throwing.","Verify parent id and optional taskId exist in tasks.json before calling.","Keep tasks.json valid JSON (lint it after manual edits or merges).","Ensure the MCP server user can write to the project directory.","Serialize writes: don't run CLI and MCP mutations on tasks.json simultaneously."],"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"}