{"id":"1b336915a24a1cd7","repo":"gorilla/mux","slug":"mux-route-does-not-have-a-path","errorCode":null,"errorMessage":"mux: route does not have a path","messagePattern":"mux: route does not have a path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"route.go","lineNumber":720,"sourceCode":"\tif r.err != nil {\n\t\treturn \"\", r.err\n\t}\n\tif r.regexp.path == nil {\n\t\treturn \"\", errors.New(\"mux: route doesn't have a path\")\n\t}\n\treturn r.regexp.path.template, nil\n}\n\n// GetPathRegexp returns the expanded regular expression used to match route path.\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 path.\nfunc (r *Route) GetPathRegexp() (string, error) {\n\tif r.err != nil {\n\t\treturn \"\", r.err\n\t}\n\tif r.regexp.path == nil {\n\t\treturn \"\", errors.New(\"mux: route does not have a path\")\n\t}\n\treturn r.regexp.path.regexp.String(), nil\n}\n\n// GetQueriesRegexp returns the expanded regular expressions used to match the\n// route queries.\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 have queries.\nfunc (r *Route) GetQueriesRegexp() ([]string, error) {\n\tif r.err != nil {\n\t\treturn nil, r.err\n\t}\n\tif r.regexp.queries == nil {\n\t\treturn nil, errors.New(\"mux: route doesn't have queries\")\n\t}\n\tqueries := make([]string, 0, len(r.regexp.queries))\n\tfor _, query := range r.regexp.queries {","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/gorilla/mux/blob/db9d1d0073d27a0a2d9a8c1bc52aa0af4374d265/route.go#L702-L738","documentation":"Returned by Route.GetPathRegexp (route.go:715-722) when introspecting the compiled path regexp of a route that has no path matcher. Note the slightly different wording ('does not have a path') versus GetPathTemplate/URLPath ('doesn't have a path') at the other call sites.","triggerScenarios":"Calling GetPathRegexp() on a host-only or method-only route during metrics/docs generation.","commonSituations":"OpenAPI generators walking all routes; tracing libraries building route labels; refactor that removes Path.","solutions":["Skip routes where GetPathRegexp errors.","Use GetPathTemplate for the human-readable template instead.","Filter to path-bearing routes first."],"exampleFix":"// before\nre, err := route.GetPathRegexp()\n// errors on host-only routes\n\n// after\nre, err := route.GetPathRegexp()\nif err != nil { re = \"\" }","handlingStrategy":"try-catch","validationCode":"re, err := route.GetPathRegexp()\nif err != nil { re = \"\" }","typeGuard":"func hasPathRe(rt *mux.Route) bool { _, err := rt.GetPathRegexp(); return err == nil }","tryCatchPattern":"re, err := rt.GetPathRegexp()\nif err != nil { continue }","preventionTips":["Treat the error as 'no path'.","Prefer GetPathTemplate for human-readable labels.","Defensive introspection in metrics/docs."],"tags":["routing","introspection","docs","regexp","path"],"analyzedSha":"db9d1d0073d27a0a2d9a8c1bc52aa0af4374d265","analyzedAt":"2026-08-04T21:35:47.097Z","schemaVersion":2}