{"record":{"id":"9bb286706a5022c8","repo":"eyaltoledano/claude-task-master","slug":"invalid-or-empty-messages-array-provided","errorCode":null,"errorMessage":"Invalid or empty messages array provided","messagePattern":"Invalid or empty messages array provided","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ai-providers/base-provider.js","lineNumber":237,"sourceCode":"\t\t\tparams.temperature !== undefined &&\n\t\t\t(params.temperature < 0 || params.temperature > 1)\n\t\t) {\n\t\t\tthrow new Error('Temperature must be between 0 and 1');\n\t\t}\n\t\tif (params.maxTokens !== undefined) {\n\t\t\tconst maxTokens = Number(params.maxTokens);\n\t\t\tif (!Number.isFinite(maxTokens) || maxTokens <= 0) {\n\t\t\t\tthrow new Error('maxTokens must be a finite number greater than 0');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Validates message array structure\n\t */\n\tvalidateMessages(messages) {\n\t\tif (!messages || !Array.isArray(messages) || messages.length === 0) {\n\t\t\tthrow new Error('Invalid or empty messages array provided');\n\t\t}\n\n\t\tfor (const msg of messages) {\n\t\t\tif (!msg.role || !msg.content) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Invalid message format. Each message must have role and content'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Common error handler\n\t */\n\thandleError(operation, error) {\n\t\tconst errorMessage = error.message || 'Unknown error occurred';\n\t\tlog('error', `${this.name} ${operation} failed: ${errorMessage}`, {\n\t\t\terror","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/src/ai-providers/base-provider.js#L219-L255","documentation":"validateMessages() ensures the messages argument is a non-empty array before calling the AI API. Beyond array-ness, each message must have role and content. Empty or malformed message arrays would otherwise cause confusing downstream provider errors or wasted API calls.","triggerScenarios":"Calling generateText/streamText/streamObject/generateObject with messages = undefined, null, [], a non-array, or an array whose entries lack role or content.","commonSituations":"Conversation history not initialized before the first call; a filtering step removed all messages; building messages from user input that arrived empty; pushing {content} without role.","solutions":["Ensure at least one message with both role and content, e.g., [{ role: 'user', content: 'Hello' }]","Guard the conversation-building code so an empty history gets a seed message","Validate each message has role and content before calling"],"exampleFix":"// before\nawait provider.generateText({ modelId, messages: [] });\n// after\nconst messages = history.length ? history : [{ role: 'user', content: prompt }];\nawait provider.generateText({ modelId, messages });","handlingStrategy":"validation","validationCode":"const valid = Array.isArray(messages) && messages.length > 0 && messages.every(m => m?.role && m?.content);\nif (!valid) throw new Error('messages must be a non-empty array of {role, content}');","typeGuard":"function isValidMessages(msgs) { return Array.isArray(msgs) && msgs.length > 0 && msgs.every(m => typeof m?.role === 'string' && typeof m?.content === 'string' && m.content.length > 0); }","tryCatchPattern":"try {\n  await provider.generateText({ modelId, messages });\n} catch (err) {\n  if (err.message === 'Invalid or empty messages array provided') {\n    messages = [{ role: 'user', content: prompt }];\n  } else throw err;\n}","preventionTips":["Always seed a conversation with at least one user message","Validate message shape right after building history, not at call time","Beware filters that can empty the messages array before a call"],"tags":["validation","messages","parameters","empty-input"],"backgroundTag":"parameter-validation-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}