{"record":{"id":"e011468a20a7f04a","repo":"eyaltoledano/claude-task-master","slug":"invalid-model-id","errorCode":"INVALID_MODEL_ID","errorMessage":"Invalid model ID: ${modelId}. Must be a non-empty string.","messagePattern":"Invalid model ID: (.+?)\\. Must be a non-empty string\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/models.js","lineNumber":420,"sourceCode":"\t}\n\n\t// Validate role\n\tif (!['main', 'research', 'fallback'].includes(role)) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tcode: 'INVALID_ROLE',\n\t\t\t\tmessage: `Invalid role: ${role}. Must be one of: main, research, fallback.`\n\t\t\t}\n\t\t};\n\t}\n\n\t// Validate model ID\n\tif (typeof modelId !== 'string' || modelId.trim() === '') {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tcode: 'INVALID_MODEL_ID',\n\t\t\t\tmessage: `Invalid model ID: ${modelId}. Must be a non-empty string.`\n\t\t\t}\n\t\t};\n\t}\n\n\ttry {\n\t\tconst availableModels = getAvailableModels(projectRoot);\n\t\tconst currentConfig = getConfig(projectRoot);\n\t\tlet determinedProvider = null; // Initialize provider\n\t\tlet warningMessage = null;\n\n\t\t// Find the model data in internal list\n\t\t// If we have a provider hint, search for exact provider+model match\n\t\t// Otherwise, just search by model ID (will get first match)\n\t\tlet modelData;\n\t\tif (providerHint) {\n\t\t\t// Search for model with specific provider\n\t\t\tmodelData = availableModels.find(","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/models.js#L402-L438","documentation":"setModel() requires a non-empty, non-whitespace string model ID. Before doing any config or provider lookup it validates typeof modelId === 'string' && modelId.trim() !== '', and returns this structured failure if not. It means the caller passed undefined/null/empty string (or a non-string) as the --model-id value.","triggerScenarios":"Calling setModel(modelId, role, projectRoot) with modelId = undefined, null, '', '   ', a number, or an object — e.g. the CLI flag --model-id was omitted or the flag was given without a value so the parsed argument is empty.","commonSituations":"Running `task-master models --set-main` without `--openrouter=<id>`/`--model-id` value; a shell variable holding the model id being unset/empty ($MODEL_ID with no default); scripting that interpolates a blank env var; typos where the value lands in the wrong flag.","solutions":["Re-run the command with an explicit non-empty model id, e.g. `task-master models --set-main --openrouter anthropic/claude-sonnet-4`.","In scripts, check the value before calling: if (typeof modelId === 'string' && modelId.trim()) await setModel(modelId, 'main', root).","If a shell/env variable supplies the id, verify it is exported and non-empty (`echo \"$MODEL_ID\"`) and add a default like ${MODEL_ID:-anthropic/claude-sonnet-4}."],"exampleFix":"// before\nawait setModel(process.env.MODEL_ID, 'main', projectRoot); // undefined if env var missing\n// after\nconst modelId = process.env.MODEL_ID?.trim();\nif (!modelId) throw new Error('MODEL_ID env var must be set');\nawait setModel(modelId, 'main', projectRoot);","handlingStrategy":"validation","validationCode":"function canSetModel(modelId) {\n  return typeof modelId === 'string' && modelId.trim() !== '';\n}\n// before calling:\nif (!canSetModel(modelId)) throw new Error('modelId must be a non-empty string');","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}\nif (isNonEmptyString(modelId)) {\n  await setModel(modelId, 'main', projectRoot);\n}","tryCatchPattern":"try {\n  const res = await setModel(modelId, 'main', projectRoot);\n  if (!res.success && res.error?.code === 'INVALID_MODEL_ID') {\n    console.error('Provide a non-empty --model-id value, e.g. --openrouter vendor/model');\n  }\n} catch (e) {\n  console.error('Unexpected setModel failure:', e.message);\n}","preventionTips":["Never interpolate raw env vars into modelId without a fallback/default value.","Validate CLI arguments (non-empty string) in your wrapper before calling setModel.","Use a constant or enum of allowed model ids instead of free-form strings in automation.","Add a shell guard: : \"${MODEL_ID:?MODEL_ID must be set}\" before invoking task-master commands."],"tags":["validation","argument-error","configuration"],"backgroundTag":"invalid-model-id","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}