labstack/echo · critical
panic: err from g.AddRoute(Route{Method: RouteNotFound, Path
Error message
panic: err from g.AddRoute(Route{Method: RouteNotFound, Path: "/*"}) What it means
Panicked inside Group.Use (group.go:48) when adding the catch-all RouteNotFound '/*' route fails during middleware auto-registration. When you call g.Use(...), Echo registers RouteNotFound routes so group middleware executes even without an exact route match. If g.AddRoute returns an error for the '/*' pattern, v4 panics (v5 will return errors instead).
Source
Thrown at group.go:48
// flag set to true. Example `echo.NewWithConfig(echo.Config{NoGroupAutoRegister404Routes: true})`.
func (g *Group) Use(middleware ...MiddlewareFunc) {
g.middleware = append(g.middleware, middleware...)
if len(g.middleware) == 0 {
return
}
if g.noAutoRegisterRoutes {
return
}
// group level middlewares are different from Echo `Pre` and `Use` middlewares (those are global). Group level middlewares
// are only executed if they are added to the Router with route.
// So we register catch all route (404 is a safe way to emulate route match) for this group and now during routing the
// Router would find route to match our request path and therefore guarantee the middleware(s) will get executed.
// Note: we use nil handler so Router would choose the default 404 handler. This may not work with custom routers.
if _, err := g.AddRoute(Route{Method: RouteNotFound, Path: "", allowOverwrite: true}); err != nil {
panic(err) // this is how `v4` handles errors. `v5` has methods to have panic-free usage
}
if _, err := g.AddRoute(Route{Method: RouteNotFound, Path: "/*", allowOverwrite: true}); err != nil {
panic(err) // this is how `v4` handles errors. `v5` has methods to have panic-free usage
}
}
// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group. Panics on error.
func (g *Group) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo {
return g.Add(http.MethodConnect, path, h, m...)
}
// DELETE implements `Echo#DELETE()` for sub-routes within the Group. Panics on error.
func (g *Group) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo {
return g.Add(http.MethodDelete, path, h, m...)
}
// GET implements `Echo#GET()` for sub-routes within the Group. Panics on error.
func (g *Group) GET(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo {
return g.Add(http.MethodGet, path, h, m...)
}
View on GitHub (pinned to 05489dc173)
Solutions
- If you don't need group middleware to run on unmatched routes, disable auto-registration: echo.NewWithConfig(echo.Config{NoGroupAutoRegister404Routes: true}).
- Ensure group prefixes are unique so the '/*' catch-all doesn't collide.
- Move middleware to route-level registration (g.Add with middleware) instead of g.Use if the catch-all is the problem.
- Check the wrapped error from AddRoute to identify the specific router conflict.
Example fix
// before: two groups, same prefix, both Use()
g1 := e.Group("/api"); g1.Use(mw)
g2 := e.Group("/api"); g2.Use(mw) // collision on RouteNotFound /*
// after: disable auto-registration globally
e := echo.NewWithConfig(echo.Config{NoGroupAutoRegister404Routes: true})
g1 := e.Group("/api"); g1.Use(mw) Defensive patterns
Strategy: validation
Validate before calling
// If you don't rely on catch-all execution, disable auto-registration up front.
e := echo.NewWithConfig(echo.Config{
NoGroupAutoRegister404Routes: true,
}) Prevention
- Set NoGroupAutoRegister404Routes:true when group middleware need not run on unmatched routes.
- Keep group prefixes unique to avoid '/*' RouteNotFound collisions.
- Prefer applying middleware at the route level via g.Add if catch-all is problematic.
When it happens
Trigger: Calling g.Use(middleware...) on a Group whose prefix already conflicts with an existing '/*' RouteNotFound registration, or when the router rejects the catch-all pattern. Also triggered by disabling auto-registration incorrectly or by registering overlapping groups with middleware.
Common situations: Two groups share the same prefix and both call Use(); custom routers that reject RouteNotFound method; conflicting route registrations detected at Use() time.
Related errors
- panic: errs collected from g.AddRoute failures in Group.Matc
- panic: err from g.AddRoute in Group.Add
- echo basic-auth middleware requires a validator function
- echo body-dump middleware requires a handler function
- invalid gzip level
AI-assisted analysis of labstack/echo@05489dc173 (2026-08-04).
Data as JSON: /data/errors/c2ccfabdc0480f62.json.
Report an issue: GitHub.