{"record":{"id":"156c9d34dfd57ff3","repo":"eyaltoledano/claude-task-master","slug":"direct-function-error","errorCode":"DIRECT_FUNCTION_ERROR","errorMessage":"${error.message}","messagePattern":"\\$\\{error\\.message\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/core/direct-functions/models.js","lineNumber":123,"sourceCode":"\t\t\tif (modelSetResult) {\n\t\t\t\treturn modelSetResult;\n\t\t\t}\n\n\t\t\t// Default action: get current configuration\n\t\t\treturn await getModelConfiguration({\n\t\t\t\tsession,\n\t\t\t\tmcpLog,\n\t\t\t\tprojectRoot\n\t\t\t});\n\t\t} finally {\n\t\t\tdisableSilentMode();\n\t\t}\n\t} catch (error) {\n\t\tlog.error(`Error in models_direct: ${error.message}`);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tcode: 'DIRECT_FUNCTION_ERROR',\n\t\t\t\tmessage: error.message,\n\t\t\t\tdetails: error.stack\n\t\t\t}\n\t\t};\n\t}\n}\n","sourceCodeStart":105,"sourceCodeEnd":130,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/models.js#L105-L130","documentation":"DIRECT_FUNCTION_ERROR is a generic catch-all error returned by the models_direct MCP direct function when an unexpected exception escapes the main try block. It wraps the underlying error message and stack trace in the standard MCP response shape. It indicates a bug, bad environment, or an unexpected failure inside the models logic rather than a validation rejection.","triggerScenarios":"Any uncaught exception thrown inside modelsDirect (e.g. reading task files fails, a utility throws, log/summary computation crashes) is caught at mcp-server/src/core/direct-functions/models.js:123 and converted to this error with the exception's message and stack as details.","commonSituations":"Corrupt or missing .taskmaster/tasks directory, unreadable tasks.json (bad JSON), permission problems on the project files, or an internal bug in a refactored helper used by models_direct.","solutions":["Read the `details` field (error.stack) in the response to find the underlying exception and its origin.","Verify the project's .taskmaster directory and tasks.json exist and contain valid JSON.","Check file permissions on .taskmaster files so the MCP server process can read them.","Reproduce the underlying error by running the equivalent `task-master models` CLI command and fix the root cause (or report a bug if the core logic itself is throwing)."],"exampleFix":"// before: response hides root cause\n{ success: false, error: { code: 'DIRECT_FUNCTION_ERROR', message: err.message } }\n// after: inspect details.stack in the response to locate the real failing call\nconst resp = await modelsDirect(args, log);\nif (!resp.success) {\n  console.error(resp.error.details); // stack trace of the real cause\n}","handlingStrategy":"try-catch","validationCode":"import fs from 'fs';\nif (!fs.existsSync('.taskmaster/tasks/tasks.json')) {\n  throw new Error('.taskmaster/tasks/tasks.json not found');\n}\nJSON.parse(fs.readFileSync('.taskmaster/tasks/tasks.json', 'utf8'));","typeGuard":"function isDirectFunctionError(resp) {\n  return resp && resp.success === false && resp.error?.code === 'DIRECT_FUNCTION_ERROR';\n}","tryCatchPattern":"const resp = await modelsDirect(args, log);\nif (!resp.success) {\n  if (resp.error.code === 'DIRECT_FUNCTION_ERROR') {\n    console.error('Underlying cause:', resp.error.details);\n  }\n  throw new Error(resp.error.message);\n}","preventionTips":["Always inspect the `details` (stack) field — the message alone hides the real cause.","Keep .taskmaster/tasks.json valid JSON and committed/backed up.","Run the equivalent CLI command (`task-master models`) locally to reproduce root causes.","Pin and test the MCP server version against your task-master version."],"tags":["mcp","unexpected-exception","catch-all","direct-function"],"backgroundTag":"direct-function-uncaught-exception","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}