{"id":"3647a65180a91450","repo":"labstack/echo","slug":"route-not-found","errorCode":null,"errorMessage":"route not found","messagePattern":"route not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"route.go","lineNumber":130,"sourceCode":"}\n\n// Clone creates copy of Routes\nfunc (r Routes) Clone() Routes {\n\tresult := make(Routes, len(r))\n\tfor i, route := range r {\n\t\tresult[i] = route.Clone()\n\t}\n\treturn result\n}\n\n// Reverse reverses route to URL string by replacing path parameters with given params values.\nfunc (r Routes) Reverse(routeName string, pathValues ...any) (string, error) {\n\tfor _, rr := range r {\n\t\tif rr.Name == routeName {\n\t\t\treturn rr.Reverse(pathValues...), nil\n\t\t}\n\t}\n\treturn \"\", errors.New(\"route not found\")\n}\n\n// FindByMethodPath searched for matching route info by method and path\nfunc (r Routes) FindByMethodPath(method string, path string) (RouteInfo, error) {\n\tif r == nil {\n\t\treturn RouteInfo{}, errors.New(\"route not found by method and path\")\n\t}\n\n\tfor _, rr := range r {\n\t\tif rr.Method == method && rr.Path == path {\n\t\t\treturn rr, nil\n\t\t}\n\t}\n\treturn RouteInfo{}, errors.New(\"route not found by method and path\")\n}\n\n// FilterByMethod searched for matching route info by method\nfunc (r Routes) FilterByMethod(method string) (Routes, error) {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/route.go#L112-L148","documentation":"Returned by Routes.Reverse(routeName, pathValues...) when no registered route has the given Name. Reverse walks the route list matching by Name; a miss means the URL cannot be generated. Route names are optional — when unset, ToRouteInfo derives a name from Method:Path, so you must reverse using the name you actually set (or the derived form).","triggerScenarios":"Calling e.Routes().Reverse(\"user.show\", id) when no route was registered with Name \"user.show\" (e.g., you forgot r.Name = \"user.show\" at registration, or the name is misspelled).","commonSituations":"Refactor renames a route's Name but not the Reverse callers; typo in the name string; or reversing before the route is registered (e.g., during package init).","solutions":["Set an explicit Name when registering: e.GET(\"/users/:id\", h).Name = \"user.show\", then Reverse(\"user.show\", id).","If you did not set Name, use the derived form Method:Path, e.g. \"GET:/users/:id\".","Check the returned error from Reverse and handle the empty-string fallback rather than passing an empty URL to the client.","Centralise route names as constants to avoid typos between registration and reversal."],"exampleFix":"// before\nurl, _ := e.Routes().Reverse(\"user.show\", 42) // name mismatch -> error, url==\"\"\n// after\ne.GET(\"/users/:id\", h).Name = \"user.show\"\nurl, err := e.Routes().Reverse(\"user.show\", 42)\nif err != nil { /* handle missing route */ }","handlingStrategy":"validation","validationCode":"func mustReverse(routes echo.Routes, name string, vals ...any) (string, error) {\n    if routes == nil {\n        return \"\", errors.New(\"no routes registered\")\n    }\n    url, err := routes.Reverse(name, vals...)\n    if err != nil {\n        return \"\", fmt.Errorf(\"reverse: %w\", err)\n    }\n    return url, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set explicit, stable Name on routes and reference them via constants to avoid typos.","Always check the error from Reverse; an empty url with nil error is impossible, but err means the URL is empty.","Register routes before any code path that calls Reverse."],"tags":["echo","router","reverse","routes","runtime"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}