labstack/echo · warning
route not found by method and path
Error message
route not found by method and path
What it means
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.
Source
Thrown at route.go:136
result[i] = route.Clone()
}
return result
}
// Reverse reverses route to URL string by replacing path parameters with given params values.
func (r Routes) Reverse(routeName string, pathValues ...any) (string, error) {
for _, rr := range r {
if rr.Name == routeName {
return rr.Reverse(pathValues...), nil
}
}
return "", errors.New("route not found")
}
// FindByMethodPath searched for matching route info by method and path
func (r Routes) FindByMethodPath(method string, path string) (RouteInfo, error) {
if r == nil {
return RouteInfo{}, errors.New("route not found by method and path")
}
for _, rr := range r {
if rr.Method == method && rr.Path == path {
return rr, nil
}
}
return RouteInfo{}, errors.New("route not found by method and path")
}
// FilterByMethod searched for matching route info by method
func (r Routes) FilterByMethod(method string) (Routes, error) {
if r == nil {
return nil, errors.New("route not found by method")
}
result := make(Routes, 0)
for _, rr := range r {View on GitHub (pinned to 05489dc173)
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.
Example fix
// before
var r echo.Routes
info, err := r.FindByMethodPath("GET", "/users/:id") // r is nil -> error
// after
routes := e.Routes()
if routes == nil {
return errors.New("no routes registered")
}
info, err := routes.FindByMethodPath("GET", "/users/:id") Defensive patterns
Strategy: validation
Validate before calling
func findByMethodPath(routes echo.Routes, method, path string) (echo.RouteInfo, error) {
if routes == nil {
return echo.RouteInfo{}, errors.New("routes table is nil; register routes first")
}
return routes.FindByMethodPath(method, path)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- route not found by method
- route not found
- ResponseWriter does not implement 'Unwrap() http.ResponseWri
- response writer flushing is not supported
- file does not implement io.ReadSeeker
AI-assisted analysis of labstack/echo@05489dc173 (2026-08-04).
Data as JSON: /data/errors/e56fc85e05b7aa17.json.
Report an issue: GitHub.