nats-io/nats-server · error
sizes defined as strings must end in K, M, G, T
Error message
sizes defined as strings must end in K, M, G, T
What it means
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.
Source
Thrown at server/opts.go:2521
return 0, fmt.Errorf("must be int64 or string")
}
if s == _EMPTY_ {
return 0, nil
}
suffix := s[len(s)-1:]
prefix := s[:len(s)-1]
num, err := strconv.ParseInt(prefix, 10, 64)
if err != nil {
return 0, err
}
suffixMap := map[string]int64{"K": 10, "M": 20, "G": 30, "T": 40}
mult, ok := suffixMap[suffix]
if !ok {
return 0, fmt.Errorf("sizes defined as strings must end in K, M, G, T")
}
num *= 1 << mult
return num, nil
}
// Parse enablement of jetstream for a server.
func parseJetStreamLimits(v any, opts *Options, errors *[]error) error {
var lt token
tk, v := unwrapValue(v, <)
opts.JetStreamLimits = JSLimitOpts{}
vv, ok := v.(map[string]any)
if !ok {
return &configErr{tk, fmt.Sprintf("Expected a map to define JetStreamLimits, got %T", v)}
}
for mk, mv := range vv {View on GitHub (pinned to 3a66a489d2)
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)
Example fix
// before limits["max_memory"] = "10MB" // after limits["max_memory"] = "10M"
Defensive patterns
Strategy: validation
Validate before calling
func validSizeString(s string) bool {
if len(s) < 2 { return false }
if _, err := strconv.ParseInt(s[:len(s)-1], 10, 64); err != nil { return false }
return strings.ContainsRune("KMGT", rune(s[len(s)-1]))
} Try / catch
if err := checkSize(s); err != nil {
log.Fatalf("config: %v (use e.g. 10K, 5M, 2G, 1T)", err)
} Prevention
- 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]$
When it happens
Trigger: 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".
Common situations: 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.
Related errors
- ack wait must be a positive value
- JS API timeout must be a positive value
- mqtt requires JetStream to be enabled if running in standalo
- must be int64 or string
- got corrupted escaped character
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/a86f05a4fa7d9a8a.
Report an issue: GitHub.