{"id":"8b5825d015bbeda6","repo":"labstack/echo","slug":"route-not-found-by-method","errorCode":null,"errorMessage":"route not found by method","messagePattern":"route not found by method","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"route.go","lineNumber":150,"sourceCode":"\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 {\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\")","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/route.go#L132-L168","documentation":"Returned by Routes.FilterByMethod when the Routes receiver is nil. The function filters all routes of a given HTTP method; a nil slice means no route table exists at all, so the guard returns early rather than pretending there are zero matching routes (which would be indistinguishable from 'method not used').","triggerScenarios":"Calling FilterByMethod on a nil Routes value: var r echo.Routes; r.FilterByMethod(http.MethodGet), or on the result of e.Routes() before any route is registered.","commonSituations":"Querying routes during package init or before Echo has registered handlers; storing the routes in an uninitialised variable; or a loader that returns nil on error.","solutions":["Call FilterByMethod only after route registration is complete.","Guard the receiver: if routes := e.Routes(); routes != nil { rs, err := routes.FilterByMethod(http.MethodGet) }.","Always inspect the returned error before using the (possibly nil) Routes result.","Prefer e.Routes() (never nil after Start) over hand-managed route slices."],"exampleFix":"// before\nvar r echo.Routes\nfiltered, err := r.FilterByMethod(http.MethodGet) // r is nil -> error\n// after\nroutes := e.Routes()\nif routes == nil {\n    return nil, errors.New(\"routes not initialised\")\n}\nfiltered, err := routes.FilterByMethod(http.MethodGet)","handlingStrategy":"validation","validationCode":"func filterByMethod(routes echo.Routes, method string) (echo.Routes, error) {\n    if routes == nil {\n        return nil, errors.New(\"routes table is nil; register routes first\")\n    }\n    return routes.FilterByMethod(strings.ToUpper(method))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call FilterByMethod after route registration is complete.","Guard the nil receiver before calling.","Use e.Routes() rather than uninitialised local variables."],"tags":["echo","router","routes","nil-guard","runtime"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}