{"id":"663993ee9adaf706","repo":"gofiber/fiber","slug":"servers-cannot-be-empty","errorCode":null,"errorMessage":"Servers cannot be empty","messagePattern":"Servers cannot be empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/proxy/config.go","lineNumber":131,"sourceCode":"\tif len(config) < 1 {\n\t\treturn ConfigDefault\n\t}\n\n\t// Override default config\n\tcfg := config[0]\n\n\t// Set default values\n\tif cfg.Timeout <= 0 {\n\t\tcfg.Timeout = ConfigDefault.Timeout\n\t}\n\n\tif cfg.MaxConnsPerHost <= 0 {\n\t\tcfg.MaxConnsPerHost = ConfigDefault.MaxConnsPerHost\n\t}\n\n\t// Set default values\n\tif len(cfg.Servers) == 0 && cfg.Client == nil {\n\t\tpanic(\"Servers cannot be empty\")\n\t}\n\treturn cfg\n}\n","sourceCodeStart":113,"sourceCodeEnd":135,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/proxy/config.go#L113-L135","documentation":"The proxy middleware configDefault() requires either a non-empty Servers list or a custom Client (a *fasthttp.LBClient). If both are unset the middleware has no upstream to forward to, so it panics with \"Servers cannot be empty\". This is a fail-fast guard ensuring the proxy cannot start without a target.","triggerScenarios":"Calling proxy.New() with a Config where Servers is nil/empty and Client is nil. This also happens when passing no config at all but intending to use Servers, or when Servers is populated from an env var that resolved to empty.","commonSituations":"Reading upstream URLs from an environment variable that is unset in the current environment. Passing a config struct built elsewhere that conditionally sets Servers. Forgetting that providing a Client disables the Servers path entirely.","solutions":["Populate Config.Servers with at least one entry like \"https://upstream.example.com\".","If you use a custom load-balancing client, set Config.Client to a non-nil *fasthttp.LBClient instead.","Validate that the env/config source for Servers is non-empty before constructing the middleware."],"exampleFix":"// before\napp.Use(proxy.New())\n// after\napp.Use(proxy.New(proxy.Config{\n    Servers: []string{\"https://upstream.example.com\"},\n}))","handlingStrategy":"validation","validationCode":"if len(cfg.Servers) == 0 && cfg.Client == nil {\n    log.Fatal(\"proxy: must provide Config.Servers or Config.Client\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Load and validate the upstream server list from env/config before constructing the proxy.","Unit-test config loading to ensure Servers is non-empty in every environment."],"tags":["proxy","config","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}