{"id":"e56fc85e05b7aa17","repo":"labstack/echo","slug":"route-not-found-by-method-and-path","errorCode":null,"errorMessage":"route not found by method and path","messagePattern":"route not found by method and path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"route.go","lineNumber":136,"sourceCode":"\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) {\n\tif r == nil {\n\t\treturn nil, errors.New(\"route not found by method\")\n\t}\n\n\tresult := make(Routes, 0)\n\tfor _, rr := range r {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/route.go#L118-L154","documentation":"Returned by Routes.FindByMethodPath when the Routes receiver itself is nil. This is distinct from a non-nil-but-empty list: a nil slice means the route table was never populated (or e.Routes() returned nil). The guard short-circuits before iterating because ranging over nil is safe but semantically there is nothing to find.","triggerScenarios":"Calling FindByMethodPath on a nil Routes value, e.g. var r echo.Routes; r.FindByMethodPath(\"GET\", \"/x\"), or using the result of a function that returns nil routes before Echo has registered any.","commonSituations":"Calling e.Routes() during init before any route is added; storing routes in a field that was never initialised; or a helper that returns nil on error and the caller forgets to check.","solutions":["Ensure you call FindByMethodPath only after routes are registered (e.g., after e.Start or at least after route registration).","Guard the receiver: if r := e.Routes(); r != nil { info, err := r.FindByMethodPath(...) }.","Always check the returned error.","Prefer e.Reverse(name) / e.URLRoutes if you just need a URL, which handle nil internally."],"exampleFix":"// before\nvar r echo.Routes\ninfo, err := r.FindByMethodPath(\"GET\", \"/users/:id\") // r is nil -> error\n// after\nroutes := e.Routes()\nif routes == nil {\n    return errors.New(\"no routes registered\")\n}\ninfo, err := routes.FindByMethodPath(\"GET\", \"/users/:id\")","handlingStrategy":"validation","validationCode":"func findByMethodPath(routes echo.Routes, method, path string) (echo.RouteInfo, error) {\n    if routes == nil {\n        return echo.RouteInfo{}, errors.New(\"routes table is nil; register routes first\")\n    }\n    return routes.FindByMethodPath(method, path)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call FindByMethodPath after routes are registered.","Guard against a nil receiver explicitly before calling.","Prefer e.Routes() (non-nil after registration) over hand-managed route slices."],"tags":["echo","router","routes","nil-guard","runtime"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}