{"record":{"id":"65b2b6044af37a84","repo":"caddyserver/caddy","slug":"weight-of-an-upstream-cannot-be-negative","errorCode":null,"errorMessage":"weight of an upstream cannot be negative","messagePattern":"weight of an upstream cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/reverseproxy/selectionpolicies.go","lineNumber":137,"sourceCode":"\treturn nil\n}\n\n// Provision sets up r.\nfunc (r *WeightedRoundRobinSelection) Provision(ctx caddy.Context) error {\n\tfor _, weight := range r.Weights {\n\t\tr.totalWeight += weight\n\t}\n\treturn nil\n}\n\n// Validate ensures that r's configuration is valid\nfunc (r *WeightedRoundRobinSelection) Validate() error {\n\tif r.totalWeight <= 0 {\n\t\treturn fmt.Errorf(\"weighted_round_robin requires at least one upstream with a positive weight\")\n\t}\n\tfor _, weight := range r.Weights {\n\t\tif weight < 0 {\n\t\t\treturn fmt.Errorf(\"weight of an upstream cannot be negative\")\n\t\t}\n\t}\n\treturn nil\n}\n\n// Select returns an available host, if any.\nfunc (r *WeightedRoundRobinSelection) Select(pool UpstreamPool, _ *http.Request, _ http.ResponseWriter) *Upstream {\n\tif len(pool) == 0 {\n\t\treturn nil\n\t}\n\tif len(r.Weights) < 2 {\n\t\treturn pool[0]\n\t}\n\tvar index, totalWeight int\n\tvar weights []int\n\n\tfor _, w := range r.Weights {\n\t\tif w > 0 {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/reverseproxy/selectionpolicies.go#L119-L155","documentation":"Error \"weight of an upstream cannot be negative\" thrown in caddyserver/caddy.","triggerScenarios":"Thrown at modules/caddyhttp/reverseproxy/selectionpolicies.go:137 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set all upstream weights to zero or a positive value."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}