{"record":{"id":"2343b680439aaeda","repo":"eyaltoledano/claude-task-master","slug":"set-model-error","errorCode":"SET_MODEL_ERROR","errorMessage":"${error.message}","messagePattern":"\\$\\{error\\.message\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/models.js","lineNumber":772,"sourceCode":"\t\tconst successMessage = `Successfully set ${role} model to ${modelId} (Provider: ${determinedProvider})`;\n\t\treport('info', successMessage);\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\trole,\n\t\t\t\tprovider: determinedProvider,\n\t\t\t\tmodelId,\n\t\t\t\tmessage: successMessage,\n\t\t\t\twarning: warningMessage // Include warning in the response data\n\t\t\t}\n\t\t};\n\t} catch (error) {\n\t\treport('error', `Error setting ${role} model: ${error.message}`);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tcode: 'SET_MODEL_ERROR',\n\t\t\t\tmessage: error.message\n\t\t\t}\n\t\t};\n\t}\n}\n\n/**\n * Get API key status for all known providers.\n * @param {Object} [options] - Options for the operation\n * @param {Object} [options.session] - Session object containing environment variables (for MCP)\n * @param {Function} [options.mcpLog] - MCP logger object (for MCP)\n * @param {string} [options.projectRoot] - Project root directory\n * @returns {Object} RESTful response with API key status report\n */\nasync function getApiKeyStatusReport(options = {}) {\n\tconst { mcpLog, projectRoot, session } = options;\n\tconst report = (level, ...args) => {\n\t\tif (mcpLog && typeof mcpLog[level] === 'function') {","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/models.js#L754-L790","documentation":"Catch-all wrapper for any unexpected exception thrown during setModel() execution (after the early validation returns). The original error's message is surfaced under the SET_MODEL_ERROR code — e.g. JSON.parse failures from a corrupted config file, or errors thrown by provider detection, config merging, or writeConfig internals.","triggerScenarios":"Any throw inside the try block: getConfig() hitting malformed JSON in .taskmaster/config.json, writeConfig throwing instead of returning falsy, filesystem exceptions (EACCES/ENOENT), or bugs in provider-resolution helpers.","commonSituations":"Hand-edited config file left with invalid JSON (trailing commas, comments); a partially written config from a previous crash; symlinked config pointing nowhere; an incompatibility between the CLI version and a manually migrated config schema.","solutions":["Read the reported error.message closely — it is the underlying cause (e.g. 'Unexpected token ... in JSON' means fix the config file).","Validate/repair .taskmaster/config.json with `node -e \"JSON.parse(require('fs').readFileSync('.taskmaster/config.json'))\"` or restore it via `task-master init`.","Run with debug output (DEBUG=task-master* task-master models ...) to get the full stack and identify the failing internal step.","Update task-master to the latest patch version; if the throw comes from library code, open an issue with the message and command used."],"exampleFix":"// before\n$ cat .taskmaster/config.json   // { \"models\": { \"main\": ..., } }  <- trailing comma\n// after — remove invalid JSON, then re-run\n$ node -e \"JSON.parse(require('fs').readFileSync('.taskmaster/config.json','utf8'))\"\n$ task-master models --set-main --openrouter anthropic/claude-sonnet-4","handlingStrategy":"try-catch","validationCode":"try {\n  JSON.parse(require('fs').readFileSync('.taskmaster/config.json', 'utf8'));\n} catch (e) {\n  throw new Error(`Config file is not valid JSON, fix before calling setModel: ${e.message}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await setModel(modelId, role, projectRoot, options);\n  if (!res.success && res.error?.code === 'SET_MODEL_ERROR') {\n    console.error(`setModel failed: ${res.error.message}`); // message names the root cause\n  }\n} catch (e) {\n  console.error('Unhandled setModel exception:', e);\n}","preventionTips":["Never hand-edit .taskmaster/config.json without re-validating it as JSON afterward.","Wrap library calls in try/catch and log the full error object, not just the code.","Keep task-master versions consistent across your tooling to avoid schema drift.","Commit a known-good config.json template and restore it if the file gets corrupted."],"tags":["exception","configuration","json"],"backgroundTag":"unexpected-exception-wrapped","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}