{"record":{"id":"0cac01618b8f627f","repo":"mastra-ai/mastra","slug":"invalid-method-type","errorCode":"INVALID_METHOD_TYPE","errorMessage":"INVALID_METHOD_TYPE","messagePattern":"INVALID_METHOD_TYPE","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/model-method-from-agent.ts","lineNumber":11,"sourceCode":"import type { AgentMethodType } from '../../agent';\nimport { ErrorCategory, ErrorDomain, MastraError } from '../../error';\nimport type { ModelMethodType } from './model.loop.types';\n\nexport function getModelMethodFromAgentMethod(methodType: AgentMethodType): ModelMethodType {\n  if (methodType === 'generate' || methodType === 'generateLegacy') {\n    return 'generate';\n  } else if (methodType === 'stream' || methodType === 'streamLegacy') {\n    return 'stream';\n  } else {\n    throw new MastraError({\n      id: 'INVALID_METHOD_TYPE',\n      domain: ErrorDomain.AGENT,\n      category: ErrorCategory.USER,\n    });\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/model-method-from-agent.ts#L1-L18","documentation":"getModelMethodFromAgentMethod converts an agent method type ('generate' | 'generateLegacy' | 'stream' | 'streamLegacy') into a ModelMethodType. Any other value is unsupported, and an AGENT/USER MastraError with id INVALID_METHOD_TYPE is thrown. Note the message is exactly 'INVALID_METHOD_TYPE' with no context about the received value.","triggerScenarios":"Passing any methodType other than the four accepted strings into getModelMethodFromAgentMethod (e.g. 'text', 'object', undefined, null, a misspelled variant).","commonSituations":"Custom agent wrappers or middleware passing through a wrong method name; API/version changes renaming agent methods; calling internal functions directly with untyped (string) input.","solutions":["Only call with 'generate', 'generateLegacy', 'stream', or 'streamLegacy'","Validate/normalize the method string before invoking; log the offending value since the error text omits it","Check for version drift if an agent method was renamed","Use TypeScript literal types so invalid values fail at compile time"],"exampleFix":"// before\nconst m = getModelMethodFromAgentMethod(userInput as string);\n// after\ntype AgentMethod = 'generate' | 'generateLegacy' | 'stream' | 'streamLegacy';\nconst method: AgentMethod = userInput === 'stream' ? 'stream' : 'generate';\nconst m = getModelMethodFromAgentMethod(method);","handlingStrategy":"type-guard","validationCode":"const VALID = ['generate', 'generateLegacy', 'stream', 'streamLegacy'] as const;\nif (!VALID.includes(methodType as any)) {\n  throw new Error(`Unsupported agent method: ${String(methodType)}`);\n}","typeGuard":"type AgentMethodType = 'generate' | 'generateLegacy' | 'stream' | 'streamLegacy';\nfunction isAgentMethodType(v: unknown): v is AgentMethodType {\n  return v === 'generate' || v === 'generateLegacy' || v === 'stream' || v === 'streamLegacy';\n}","tryCatchPattern":"try {\n  const m = getModelMethodFromAgentMethod(raw as AgentMethodType);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'INVALID_METHOD_TYPE') {\n    console.error(`Invalid method value received: ${String(raw)}`);\n  }\n  throw e;\n}","preventionTips":["Type method inputs with the literal union so invalid values fail at compile time","Keep a mapping table of agent method names in one place to avoid drift across versions","Log the raw input before calling since the error message omits the offending value"],"tags":["agent","typescript","invalid-argument","user-error"],"backgroundTag":"invalid-enum-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}