{"id":"6e6a4241efc755f2","repo":"labstack/echo","slug":"route-not-found-by-path","errorCode":null,"errorMessage":"route not found by path","messagePattern":"route not found by path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"route.go","lineNumber":168,"sourceCode":"\t\treturn nil, errors.New(\"route not found by method\")\n\t}\n\n\tresult := make(Routes, 0)\n\tfor _, rr := range r {\n\t\tif rr.Method == method {\n\t\t\tresult = append(result, rr)\n\t\t}\n\t}\n\tif len(result) == 0 {\n\t\treturn nil, errors.New(\"route not found by method\")\n\t}\n\treturn result, nil\n}\n\n// FilterByPath searched for matching route info by path\nfunc (r Routes) FilterByPath(path string) (Routes, error) {\n\tif r == nil {\n\t\treturn nil, errors.New(\"route not found by path\")\n\t}\n\n\tresult := make(Routes, 0)\n\tfor _, rr := range r {\n\t\tif rr.Path == path {\n\t\t\tresult = append(result, rr)\n\t\t}\n\t}\n\tif len(result) == 0 {\n\t\treturn nil, errors.New(\"route not found by path\")\n\t}\n\treturn result, nil\n}\n\n// FilterByName searched for matching route info by name\nfunc (r Routes) FilterByName(name string) (Routes, error) {\n\tif r == nil {\n\t\treturn nil, errors.New(\"route not found by name\")","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/route.go#L150-L186","documentation":"Returned by Routes.FilterByPath (route.go:167-169) when the receiver Routes slice is nil. This is a programming error: a route-lookup helper was invoked on a nil collection instead of on the result of e.Routes() (router.go:379). The nil check fires before any path comparison is attempted.","triggerScenarios":"Calling FilterByPath on an uninitialized echo.Routes variable, e.g. `var rs echo.Routes; rs.FilterByPath(\"/users\")`, or invoking it on a variable that was assigned from a failed/early-return path.","commonSituations":"Refactors that drop the `routes := e.Routes()` assignment; calling Filters before any route is registered; storing a Routes field that is never populated.","solutions":["Call FilterByPath on the non-nil collection returned by e.Routes()","Nil-check the Routes variable before calling: if rs != nil { ... }","Ensure registration code ran before the lookup by asserting len(e.Routes()) > 0"],"exampleFix":"// before\nvar rs echo.Routes\nfiltered, err := rs.FilterByPath(\"/users\")\n// after\nfiltered, err := e.Routes().FilterByPath(\"/users\")","handlingStrategy":"validation","validationCode":"routes := e.Routes()\nif routes == nil {\n    return fmt.Errorf(\"no routes registered\")\n}\nfiltered, err := routes.FilterByPath(\"/users\")","typeGuard":"func routesInitialized(r echo.Routes) bool {\n    return r != nil\n}","tryCatchPattern":null,"preventionTips":["Always derive Routes from e.Routes() at the call site rather than holding a separate variable","Nil-check collections returned from optional setup steps before calling filter helpers"],"tags":["routing","nil-check"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}