{"record":{"id":"b44bd4ceffdfda15","repo":"mastra-ai/mastra","slug":"mastra-server-api-invalid-route-options","errorCode":"MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS","errorMessage":"Invalid options for route \"${path}\", missing \"method\" property","messagePattern":"Invalid options for route \"(.+?)\", missing \"method\" property","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/server/index.ts","lineNumber":98,"sourceCode":"   */\n  cors?: CorsOptions;\n  /**\n   * When false, skips Mastra auth for this route (defaults to true)\n   */\n  requiresAuth?: boolean;\n  /**\n   * Explicit RBAC permission for the route.\n   */\n  requiresPermission?: ApiRoute['requiresPermission'];\n  /**\n   * Optional FGA configuration for resource-level authorization.\n   */\n  fga?: ApiRoute['fga'];\n};\n\nfunction validateOptions<P extends string>(path: P, options: RegisterApiRouteOptions<P>): void {\n  if (options.method === undefined) {\n    throw new MastraError({\n      id: 'MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS',\n      text: `Invalid options for route \"${path}\", missing \"method\" property`,\n      domain: ErrorDomain.MASTRA_SERVER,\n      category: ErrorCategory.USER,\n    });\n  }\n\n  if (options.handler === undefined && options.createHandler === undefined) {\n    throw new MastraError({\n      id: 'MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS',\n      text: `Invalid options for route \"${path}\", you must define a \"handler\" or \"createHandler\" property`,\n      domain: ErrorDomain.MASTRA_SERVER,\n      category: ErrorCategory.USER,\n    });\n  }\n\n  if (options.handler !== undefined && options.createHandler !== undefined) {\n    throw new MastraError({","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/server/index.ts#L80-L116","documentation":"Mastra validates every API route registered via registerApiRoute before mounting it on the Hono server. This error is thrown when the route options object omits the required 'method' property, which tells the server which HTTP verb the route handles. It fails fast at registration time so misconfigured routes never reach the running server.","triggerScenarios":"Calling registerApiRoute(path, {...}) with an options object that lacks a 'method' field entirely — e.g. registerApiRoute('/my-route', { handler: async (c) => c.json({}) }).","commonSituations":"Hand-writing route configs instead of using the typed RegisterApiRouteOptions helper; building routes dynamically from a plain object (e.g. from JSON config) where the method key was never set; refactoring away from an older route definition style that inferred the method elsewhere.","solutions":["Add a 'method' property to the route options with a valid HTTP verb (e.g. method: 'GET').","If routes come from external config, validate/transform the config into RegisterApiRouteOptions before calling registerApiRoute.","Check for typos such as 'methods' or 'httpMethod' instead of 'method'."],"exampleFix":"// before\nregisterApiRoute('/users', {\n  handler: async (c) => c.json({ ok: true }),\n});\n// after\nregisterApiRoute('/users', {\n  method: 'GET',\n  handler: async (c) => c.json({ ok: true }),\n});","handlingStrategy":"validation","validationCode":"function assertRouteHasMethod(path, options) {\n  if (options == null || options.method === undefined) {\n    throw new TypeError(`Route \"${path}\" is missing required \"method\" property`);\n  }\n}\n// call before registerApiRoute(path, options)","typeGuard":"function hasMethod(o) {\n  return typeof o === 'object' && o !== null && 'method' in o && typeof o.method === 'string';\n}","tryCatchPattern":"try {\n  registerApiRoute(path, options);\n} catch (e) {\n  if (String(e?.message).includes('missing \"method\" property')) {\n    console.error(`Route ${path} config invalid: add a method`);\n  } else throw e;\n}","preventionTips":["Type route configs as RegisterApiRouteOptions so TypeScript flags a missing method at compile time.","Never build route options as untyped plain objects from JSON configs without a validation step.","Define a factory helper that always fills in method with a default (e.g. 'GET')."],"tags":["server","api-routes","validation","config"],"backgroundTag":"missing-required-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}