{"record":{"id":"9ae739c8027d4720","repo":"nats-io/nats-server","slug":"individual-weights-need-to-be-100","errorCode":null,"errorMessage":"individual weights need to be <= 100","messagePattern":"individual weights need to be <= 100","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/accounts.go","lineNumber":812,"sourceCode":"func (a *Account) AddWeightedMappings(src string, dests ...*MapDest) error {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\n\tif !IsValidSubject(src) {\n\t\treturn ErrBadSubject\n\t}\n\n\tm := &mapping{src: src, wc: subjectHasWildcard(src), dests: make([]*destination, 0, len(dests)+1)}\n\tseen := make(map[string]struct{})\n\n\tvar tw = make(map[string]uint8)\n\tfor _, d := range dests {\n\t\tif _, ok := seen[d.Subject]; ok {\n\t\t\treturn fmt.Errorf(\"duplicate entry for %q\", d.Subject)\n\t\t}\n\t\tseen[d.Subject] = struct{}{}\n\t\tif d.Weight > 100 {\n\t\t\treturn fmt.Errorf(\"individual weights need to be <= 100\")\n\t\t}\n\t\ttw[d.Cluster] += d.Weight\n\t\tif tw[d.Cluster] > 100 {\n\t\t\treturn fmt.Errorf(\"total weight needs to be <= 100\")\n\t\t}\n\t\terr := ValidateMapping(src, d.Subject)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\ttr, err := NewSubjectTransform(src, d.Subject)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif d.Cluster == _EMPTY_ {\n\t\t\tm.dests = append(m.dests, &destination{tr, d.Weight})\n\t\t} else {\n\t\t\t// We have a cluster scoped filter.\n\t\t\tif m.cdests == nil {","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/accounts.go#L794-L830","documentation":"Thrown by NATS server account mapping weight validation (server/accounts.go:812). When validating weighted destination mappings for an account's mapping, each individual destination weight must be a percentage <= 100. The server rejects the whole mapping as soon as any single entry exceeds 100.","triggerScenarios":"Calling account mapping APIs (e.g. AddMapping / NewWeightedMappings) with a WeightedMapping whose Weight field is > 100, or submitting a config with weight values over 100.","commonSituations":"Config typos like weight: 150, confusing weights (percent) with plain integers, or generating weights programmatically without bounding them.","solutions":["Set each mapping weight to a value between 0 and 100.","Treat weights as percentages of total traffic for that cluster; ensure per-cluster totals also stay <= 100.","Validate config with nats server config validation before applying."],"exampleFix":"// before\nmappings.AddWeightedMapping(dests, WeightedDestination{Cluster: \"A\", Subject: \"foo\", Weight: 150})\n// after\nmappings.AddWeightedMapping(dests, WeightedDestination{Cluster: \"A\", Subject: \"foo\", Weight: 75})","handlingStrategy":"validation","validationCode":"for _, d := range dests {\n    if d.Weight > 100 || d.Weight < 0 {\n        return fmt.Errorf(\"weight %d out of range for %s\", d.Weight, d.Subject)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := acc.AddMapping(...); err != nil {\n    if strings.Contains(err.Error(), \"<= 100\") {\n        // clamp or reject config\n    }\n}","preventionTips":["Clamp weights to [0,100] at config parse time","Document weights as percentages","Run config validation before applying mappings"],"tags":["nats-server","config-validation","weighted-mapping"],"backgroundTag":"mapping-weight-out-of-range","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}