{"record":{"id":"a86f05a4fa7d9a8a","repo":"nats-io/nats-server","slug":"sizes-defined-as-strings-must-end-in-k-m-g-t","errorCode":null,"errorMessage":"sizes defined as strings must end in K, M, G, T","messagePattern":"sizes defined as strings must end in K, M, G, T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/opts.go","lineNumber":2521,"sourceCode":"\t\treturn 0, fmt.Errorf(\"must be int64 or string\")\n\t}\n\n\tif s == _EMPTY_ {\n\t\treturn 0, nil\n\t}\n\n\tsuffix := s[len(s)-1:]\n\tprefix := s[:len(s)-1]\n\tnum, err := strconv.ParseInt(prefix, 10, 64)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\tsuffixMap := map[string]int64{\"K\": 10, \"M\": 20, \"G\": 30, \"T\": 40}\n\n\tmult, ok := suffixMap[suffix]\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"sizes defined as strings must end in K, M, G, T\")\n\t}\n\tnum *= 1 << mult\n\n\treturn num, nil\n}\n\n// Parse enablement of jetstream for a server.\nfunc parseJetStreamLimits(v any, opts *Options, errors *[]error) error {\n\tvar lt token\n\ttk, v := unwrapValue(v, &lt)\n\n\topts.JetStreamLimits = JSLimitOpts{}\n\n\tvv, ok := v.(map[string]any)\n\tif !ok {\n\t\treturn &configErr{tk, fmt.Sprintf(\"Expected a map to define JetStreamLimits, got %T\", v)}\n\t}\n\tfor mk, mv := range vv {","sourceCodeStart":2503,"sourceCodeEnd":2539,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/opts.go#L2503-L2539","documentation":"getStorageSize() accepts string sizes only when they end in one of the unit suffixes K, M, G, or T (shifted by 10/20/30/40 bits). Any other final character (or a bare number string) causes this error. Bare numeric strings are rejected because there is no default unit.","triggerScenarios":"Configuring a JetStream storage/memory limit as a string whose last character is not K, M, G, or T, e.g. \"1024\", \"10MB\", \"1kb\" (lowercase), or \"5B\".","commonSituations":"Writing \"10MB\" or \"1gb\" instead of \"10M\"/\"1G\" (no B allowed, uppercase only); leaving a plain number string without a unit; copy-pasting sizes from other tools that use KB/MB notation.","solutions":["Change the string to end with a single uppercase K, M, G, or T, e.g. \"10M\"","Remove a trailing 'B' (\"10MB\" -> \"10M\")","Uppercase lowercase suffixes (\"1kb\" -> \"1K\")","Add an explicit unit to a bare numeric string (\"1024\" -> \"1K\" or use int64 bytes)"],"exampleFix":"// before\nlimits[\"max_memory\"] = \"10MB\"\n// after\nlimits[\"max_memory\"] = \"10M\"","handlingStrategy":"validation","validationCode":"func validSizeString(s string) bool {\n\tif len(s) < 2 { return false }\n\tif _, err := strconv.ParseInt(s[:len(s)-1], 10, 64); err != nil { return false }\n\treturn strings.ContainsRune(\"KMGT\", rune(s[len(s)-1]))\n}","typeGuard":null,"tryCatchPattern":"if err := checkSize(s); err != nil {\n\tlog.Fatalf(\"config: %v (use e.g. 10K, 5M, 2G, 1T)\", err)\n}","preventionTips":["Use single uppercase unit letters without 'B' (M not MB)","Never write bare numeric strings — add a unit or use an int","Add a config linter that checks all size fields against ^[0-9]+[KMGT]$"],"tags":["config","jetstream","size-format"],"backgroundTag":"invalid-size-suffix","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}