{"record":{"id":"7421e9d62c64e0cb","repo":"eyaltoledano/claude-task-master","slug":"command-failed-with-exit-code-result-status","errorCode":null,"errorMessage":"Command failed with exit code ${result.status}: ${errorOutput}","messagePattern":"Command failed with exit code (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/tools/utils.js","lineNumber":389,"sourceCode":"\t\t// If global CLI is not available, try fallback to the local script\n\t\tif (result.error && result.error.code === 'ENOENT') {\n\t\t\tlog.info('Global task-master not found, falling back to local script');\n\t\t\t// Pass the same spawnOptions (including env) to the fallback\n\t\t\tresult = spawnSync('node', ['scripts/dev.js', ...fullArgs], spawnOptions);\n\t\t}\n\n\t\tif (result.error) {\n\t\t\tthrow new Error(`Command execution error: ${result.error.message}`);\n\t\t}\n\n\t\tif (result.status !== 0) {\n\t\t\t// Improve error handling by combining stderr and stdout if stderr is empty\n\t\t\tconst errorOutput = result.stderr\n\t\t\t\t? result.stderr.trim()\n\t\t\t\t: result.stdout\n\t\t\t\t\t? result.stdout.trim()\n\t\t\t\t\t: 'Unknown error';\n\t\t\tthrow new Error(\n\t\t\t\t`Command failed with exit code ${result.status}: ${errorOutput}`\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tstdout: result.stdout,\n\t\t\tstderr: result.stderr\n\t\t};\n\t} catch (error) {\n\t\tlog.error(`Error executing task-master command: ${error.message}`);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: error.message\n\t\t};\n\t}\n}\n","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/tools/utils.js#L371-L407","documentation":"When the spawned task-master CLI process launches but exits with a non-zero status, executeTaskMasterCommand throws this error containing the exit code and the process's stderr (or stdout fallback, or 'Unknown error'). It signals the underlying command ran and failed, unlike the spawn-level failure error.","triggerScenarios":"Any task-master subcommand failing at runtime: invalid arguments, unreadable .taskmaster directory, API/key errors inside the CLI, unhandled CLI exceptions.","commonSituations":"Missing PRD/tasks files in the project; invalid model or API key configured for the CLI; passing unsupported tool arguments through the MCP tool; Node version incompatibilities with the CLI.","solutions":["Read the errorOutput portion of the message — it contains the CLI's actual stderr/stdout diagnosis.","Run the same command manually in a terminal to reproduce and see full output.","Verify project setup (.taskmaster directory, PRD, config) and API keys the CLI needs.","Check argument forwarding: confirm fullArgs matches what the CLI expects."],"exampleFix":"// before\nawait executeTaskMasterCommand(['list', '--bad-flag']); // exit code 1: unknown option\n// after\nawait executeTaskMasterCommand(['list']); // valid args\n","handlingStrategy":"try-catch","validationCode":"// Validate args before invoking: const known = new Set(['list','parse-prd','next',...]); if (!known.has(args[0])) throw new Error('Unknown task-master subcommand');","typeGuard":"null","tryCatchPattern":"try { const r = await executeTaskMasterCommand(args); } catch (e) { const m = e.message.match(/^Command failed with exit code (\\d+): ([\\s\\S]*)$/); if (m) { logger.error('CLI failed', { exitCode: +m[1], output: m[2] }); return { success: false, stderr: m[2] }; } throw e; }","preventionTips":["Reproduce failing commands manually to read full stderr","Verify project setup (.taskmaster dir, PRD, API keys) before invoking","Validate tool arguments against the CLI's accepted flags","Keep CLI and server versions in sync"],"tags":["process","cli","exit-code","subprocess"],"backgroundTag":"nonzero-exit-code","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}