{"id":"da35f98ab754dce7","repo":"gin-gonic/gin","slug":"too-many-parameters","errorCode":null,"errorMessage":"too many parameters","messagePattern":"too many parameters","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"utils.go","lineNumber":159,"sourceCode":"\tif lastChar(relativePath) == '/' && lastChar(finalPath) != '/' {\n\t\treturn finalPath + \"/\"\n\t}\n\treturn finalPath\n}\n\nfunc resolveAddress(addr []string) string {\n\tswitch len(addr) {\n\tcase 0:\n\t\tif port := os.Getenv(\"PORT\"); port != \"\" {\n\t\t\tdebugPrint(\"Environment variable PORT=\\\"%s\\\"\", port)\n\t\t\treturn \":\" + port\n\t\t}\n\t\tdebugPrint(\"Environment variable PORT is undefined. Using port :8080 by default\")\n\t\treturn \":8080\"\n\tcase 1:\n\t\treturn addr[0]\n\tdefault:\n\t\tpanic(\"too many parameters\")\n\t}\n}\n\n// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters\nfunc isASCII(s string) bool {\n\tfor i := range len(s) {\n\t\tif s[i] > unicode.MaxASCII {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n// safeInt8 converts int to int8 safely, capping at math.MaxInt8\nfunc safeInt8(n int) int8 {\n\tif n > math.MaxInt8 {\n\t\treturn math.MaxInt8\n\t}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/gin-gonic/gin/blob/34dac209ffb6ef85cc78c5d217bbb7ad001d68fd/utils.go#L141-L177","documentation":"Thrown by resolveAddress in utils.go:159 when Engine.Run is called with more than one address argument. resolveAddress accepts a variadic addr []string but only knows how to choose a single bind address: zero args means 'use $PORT or :8080', one arg means 'use it literally', and two or more is ambiguous so it panics. Run, RunListener-related helpers, and any caller that forwards a variadic address list into resolveAddress can trigger it.","triggerScenarios":"Calling r.Run(\":8080\", \":8081\"), r.Run(addr1, addr2), or forwarding a variadic []string of unknown length into Run, e.g. r.Run(args...) where len(args) > 1.","commonSituations":"Refactoring a main() that used to flag-parse a single address and accidentally passing two; forwarding os.Args or a CLI library's string slice directly into Run; copy-pasting a dual-stack (TCP + TLS) pattern into a single Run call instead of using Run + RunTLS separately.","solutions":["Pass at most one address: r.Run(\":8080\") or r.Run() to use $PORT / :8080.","If you have a slice of unknown length, take the first element explicitly: r.Run(addrs[0]) after checking len(addrs) >= 1.","For multi-address or TLS setups, run the listeners manually: start one goroutine per address with r.Run / r.RunTLS / r.RunListener, or use http.Server with Engine as handler."],"exampleFix":"// before\nr.Run(\":8080\", \":8081\") // panics: too many parameters\n\n// after — single address\nr.Run(\":8080\")\n\n// multi-address — separate goroutines\ngo func() { _ = r.Run(\":8080\") }()\nr.RunTLS(\":8443\", \"cert.pem\", \"key.pem\")","handlingStrategy":"validation","validationCode":"// Validate the variadic address slice before forwarding it to Engine.Run.\nfunc resolveAddrSafe(addr []string) (string, error) {\n    switch len(addr) {\n    case 0:\n        return \":8080\", nil // or read $PORT\n    case 1:\n        return addr[0], nil\n    default:\n        return \"\", fmt.Errorf(\"too many addresses (%d); pass at most one to Run\", len(addr))\n    }\n}\n\n// usage\naddr, err := resolveAddrSafe(addrs)\nif err != nil { log.Fatal(err) }\n_ = r.Run(addr)","typeGuard":null,"tryCatchPattern":"func runSafe(e *gin.Engine, addr ...string) (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"Run(%v): %v\", addr, r)\n        }\n    }()\n    return e.Run(addr...)\n}","preventionTips":["Never forward an unbounded variadic slice into Run; take the first element explicitly.","Use r.Run() with no args and the $PORT env var in production (twelve-factor style).","For multi-address or mixed TCP/TLS, start one goroutine per listener rather than passing multiple addresses to a single Run.","When integrating a CLI library (cobra, urfave/cli), bind exactly one --addr flag and pass that single value."],"tags":["server-startup","address","config","gin","startup-panic"],"analyzedSha":"34dac209ffb6ef85cc78c5d217bbb7ad001d68fd","analyzedAt":"2026-08-04T21:26:18.438Z","schemaVersion":2}