{"id":"c2ccfabdc0480f62","repo":"labstack/echo","slug":"panic-err-from-g-addroute-route-method-routenotf","errorCode":null,"errorMessage":"panic: err from g.AddRoute(Route{Method: RouteNotFound, Path: \"/*\"})","messagePattern":"panic: err from g\\.AddRoute\\(Route(.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"group.go","lineNumber":48,"sourceCode":"// flag set to true. Example `echo.NewWithConfig(echo.Config{NoGroupAutoRegister404Routes: true})`.\nfunc (g *Group) Use(middleware ...MiddlewareFunc) {\n\tg.middleware = append(g.middleware, middleware...)\n\tif len(g.middleware) == 0 {\n\t\treturn\n\t}\n\tif g.noAutoRegisterRoutes {\n\t\treturn\n\t}\n\t// group level middlewares are different from Echo `Pre` and `Use` middlewares (those are global). Group level middlewares\n\t// are only executed if they are added to the Router with route.\n\t// So we register catch all route (404 is a safe way to emulate route match) for this group and now during routing the\n\t// Router would find route to match our request path and therefore guarantee the middleware(s) will get executed.\n\t// Note: we use nil handler so Router would choose the default 404 handler. This may not work with custom routers.\n\tif _, err := g.AddRoute(Route{Method: RouteNotFound, Path: \"\", allowOverwrite: true}); err != nil {\n\t\tpanic(err) // this is how `v4` handles errors. `v5` has methods to have panic-free usage\n\t}\n\tif _, err := g.AddRoute(Route{Method: RouteNotFound, Path: \"/*\", allowOverwrite: true}); err != nil {\n\t\tpanic(err) // this is how `v4` handles errors. `v5` has methods to have panic-free usage\n\t}\n}\n\n// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group. Panics on error.\nfunc (g *Group) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo {\n\treturn g.Add(http.MethodConnect, path, h, m...)\n}\n\n// DELETE implements `Echo#DELETE()` for sub-routes within the Group. Panics on error.\nfunc (g *Group) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo {\n\treturn g.Add(http.MethodDelete, path, h, m...)\n}\n\n// GET implements `Echo#GET()` for sub-routes within the Group. Panics on error.\nfunc (g *Group) GET(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo {\n\treturn g.Add(http.MethodGet, path, h, m...)\n}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/group.go#L30-L66","documentation":"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).","triggerScenarios":"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.","commonSituations":"Two groups share the same prefix and both call Use(); custom routers that reject RouteNotFound method; conflicting route registrations detected at Use() time.","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."],"exampleFix":"// before: two groups, same prefix, both Use()\ng1 := e.Group(\"/api\"); g1.Use(mw)\ng2 := e.Group(\"/api\"); g2.Use(mw) // collision on RouteNotFound /*\n// after: disable auto-registration globally\ne := echo.NewWithConfig(echo.Config{NoGroupAutoRegister404Routes: true})\ng1 := e.Group(\"/api\"); g1.Use(mw)","handlingStrategy":"validation","validationCode":"// If you don't rely on catch-all execution, disable auto-registration up front.\ne := echo.NewWithConfig(echo.Config{\n    NoGroupAutoRegister404Routes: true,\n})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["group","router","middleware","panic","startup"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}