labstack/echo · error

route not found by path

Error message

route not found by path

What it means

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.

Source

Thrown at route.go:168

		return nil, errors.New("route not found by method")
	}

	result := make(Routes, 0)
	for _, rr := range r {
		if rr.Method == method {
			result = append(result, rr)
		}
	}
	if len(result) == 0 {
		return nil, errors.New("route not found by method")
	}
	return result, nil
}

// FilterByPath searched for matching route info by path
func (r Routes) FilterByPath(path string) (Routes, error) {
	if r == nil {
		return nil, errors.New("route not found by path")
	}

	result := make(Routes, 0)
	for _, rr := range r {
		if rr.Path == path {
			result = append(result, rr)
		}
	}
	if len(result) == 0 {
		return nil, errors.New("route not found by path")
	}
	return result, nil
}

// FilterByName searched for matching route info by name
func (r Routes) FilterByName(name string) (Routes, error) {
	if r == nil {
		return nil, errors.New("route not found by name")

View on GitHub (pinned to 05489dc173)

Solutions

  1. Call FilterByPath on the non-nil collection returned by e.Routes()
  2. Nil-check the Routes variable before calling: if rs != nil { ... }
  3. Ensure registration code ran before the lookup by asserting len(e.Routes()) > 0

Example fix

// before
var rs echo.Routes
filtered, err := rs.FilterByPath("/users")
// after
filtered, err := e.Routes().FilterByPath("/users")
Defensive patterns

Strategy: validation

Validate before calling

routes := e.Routes()
if routes == nil {
    return fmt.Errorf("no routes registered")
}
filtered, err := routes.FilterByPath("/users")

Type guard

func routesInitialized(r echo.Routes) bool {
    return r != nil
}

Prevention

When it happens

Trigger: 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.

Common situations: Refactors that drop the `routes := e.Routes()` assignment; calling Filters before any route is registered; storing a Routes field that is never populated.

Related errors


AI-assisted analysis of labstack/echo@05489dc173 (2026-08-04). Data as JSON: /data/errors/6e6a4241efc755f2.json. Report an issue: GitHub.