{"record":{"id":"c86747aac31090a0","repo":"kataras/iris","slug":"new-route-s-conflicts-with-an-already-registered","errorCode":null,"errorMessage":"new route: %s conflicts with an already registered one: %s route","messagePattern":"new route: (.+?) conflicts with an already registered one: (.+?) route","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/router/api_builder.go","lineNumber":122,"sourceCode":"\t\t\t\trepo.routes = append(cp, repo.routes[i+1:]...)\n\t\t\t}\n\n\t\t\tdelete(repo.paths, r.tmpl.Src)\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc (repo *repository) register(route *Route, rule RouteRegisterRule) (*Route, error) {\n\tfor i, r := range repo.routes {\n\t\t// 14 August 2019 allow register same path pattern with different macro functions,\n\t\t// see #1058\n\t\tif route.DeepEqual(r) {\n\t\t\tif rule == RouteSkip {\n\t\t\t\treturn r, nil\n\t\t\t} else if rule == RouteError {\n\t\t\t\treturn nil, fmt.Errorf(\"new route: %s conflicts with an already registered one: %s route\", route.String(), r.String())\n\t\t\t} else if rule == RouteOverlap {\n\t\t\t\toverlapRoute(r, route)\n\t\t\t\treturn route, nil\n\t\t\t} else {\n\t\t\t\t// replace existing with the latest one, the default behavior.\n\t\t\t\trepo.routes = append(repo.routes[:i], repo.routes[i+1:]...)\n\t\t\t}\n\n\t\t\tbreak // continue\n\t\t}\n\t}\n\n\trepo.routes = append(repo.routes, route)\n\n\tif route.StatusCode == 0 { // a common resource route, not a status code error handler.\n\t\tif repo.paths == nil {\n\t\t\trepo.paths = make(map[string]*Route)\n\t\t}","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/core/router/api_builder.go#L104-L140","documentation":"When registering a route whose path pattern matches an already-registered route (and both are considered equal by DeepEqual), the router checks the RouteRegisterRule. With rule == RouteError the registration is rejected with this error instead of silently replacing or overlapping the existing route.","triggerScenarios":"Calling app.Handle/PartyHandle twice with the exact same method + path pattern (same static path, same parameters and same macro functions) while iris.RouteError register rule is configured via app.SetRegisterRule(iris.RouteError).","commonSituations":"Copy-pasting route registrations across refactors; registering the same endpoint in two init/setup functions; middleware or plugin code re-registering a route; switching the register rule to RouteError to surface accidental duplicates.","solutions":["Remove or rename the duplicate route registration (change method or path)","Change the register rule to iris.RouteOverlap or iris.RouteSkip or the default RouteReplace if the duplicate is intentional","Guard registrations with a check on whether the route already exists before calling Handle","Consolidate route setup into a single location to avoid double registration"],"exampleFix":"// before\napp.SetRegisterRule(iris.RouteError)\napp.Get(\"/users\", listUsers)\napp.Get(\"/users\", listUsers) // panics-free error at build\n// after\napp.Get(\"/users\", listUsers)\napp.Get(\"/users/{id:uint}\", getUser)","handlingStrategy":"validation","validationCode":"func routeExists(app *iris.Application, method, path string) bool {\n    for _, r := range app.Routes() {\n        if r.Method == method && r.Path == path { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"_, err := app.Handle(method, path, handler)\nif err != nil && strings.Contains(err.Error(), \"conflicts with an already registered one\") {\n    log.Fatalf(\"duplicate route: %v\", err)\n}","preventionTips":["Keep all route registrations in one place or one package","Use distinct paths/methods for handlers with the same name","Only use iris.RouteError rule when you want strict duplicate detection","Run integration tests that build the app so duplicates fail in CI"],"tags":["go","routing","duplicate-route","iris"],"backgroundTag":"duplicate-route-registration","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}