{"id":"b31fce42032430af","repo":"gorilla/mux","slug":"mux-route-doesn-t-have-methods","errorCode":null,"errorMessage":"mux: route doesn't have methods","messagePattern":"mux: route doesn't have methods","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"route.go","lineNumber":776,"sourceCode":"\t\tqueries = append(queries, query.template)\n\t}\n\treturn queries, nil\n}\n\n// GetMethods returns the methods the route matches against\n// This is useful for building simple REST API documentation and for instrumentation\n// against third-party services.\n// An error will be returned if route does not have methods.\nfunc (r *Route) GetMethods() ([]string, error) {\n\tif r.err != nil {\n\t\treturn nil, r.err\n\t}\n\tfor _, m := range r.matchers {\n\t\tif methods, ok := m.(methodMatcher); ok {\n\t\t\treturn []string(methods), nil\n\t\t}\n\t}\n\treturn nil, errors.New(\"mux: route doesn't have methods\")\n}\n\n// GetHostTemplate returns the template used to build the\n// route match.\n// This is useful for building simple REST API documentation and for instrumentation\n// against third-party services.\n// An error will be returned if the route does not define a host.\nfunc (r *Route) GetHostTemplate() (string, error) {\n\tif r.err != nil {\n\t\treturn \"\", r.err\n\t}\n\tif r.regexp.host == nil {\n\t\treturn \"\", errors.New(\"mux: route doesn't have a host\")\n\t}\n\treturn r.regexp.host.template, nil\n}\n\n// GetVarNames returns the names of all variables added by regexp matchers","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/gorilla/mux/blob/db9d1d0073d27a0a2d9a8c1bc52aa0af4374d265/route.go#L758-L794","documentation":"Returned by Route.GetMethods (route.go:767-776) when iterating the route's matchers and none is a methodMatcher, i.e. .Methods(...) was never called on the route (it accepts every method).","triggerScenarios":"Calling GetMethods() on a route with no method constraint, e.g. r.HandleFunc(\"/health\", h) without .Methods(...).","commonSituations":"OpenAPI generators expecting every route to declare verbs; metrics labeling; routes relying on a catch-all handler.","solutions":["Treat the error as 'route accepts all methods' and default to a wildcard.","Call .Methods(...) on routes that should declare verbs.","Default to [\"*\"] or []string{} in docs when it errors."],"exampleFix":"// before\nms, err := route.GetMethods()\n\n// after\nms, err := route.GetMethods()\nif err != nil { ms = []string{\"*\"} } // accepts all","handlingStrategy":"try-catch","validationCode":"ms, err := route.GetMethods()\nif err != nil { ms = []string{\"*\"} } // accepts all methods","typeGuard":"func hasMethods(rt *mux.Route) bool { _, err := rt.GetMethods(); return err == nil }","tryCatchPattern":"ms, err := rt.GetMethods()\nif err != nil { ms = nil }","preventionTips":["Always declare Methods on routes meant for docs.","Treat the error as a wildcard.","Defensive introspection."],"tags":["routing","introspection","method","docs"],"analyzedSha":"db9d1d0073d27a0a2d9a8c1bc52aa0af4374d265","analyzedAt":"2026-08-04T21:35:47.097Z","schemaVersion":2}