chenhg5/cc-connect · error
log size %q: must be non-negative
Error message
log size %q: must be non-negative
What it means
ParseLogSize rejects parsed numeric values below zero. A negative log size is meaningless (rotational size limits must be non-negative), so the parser fails fast with a message echoing the original input.
Source
Thrown at daemon/logsize.go:79
// Explicit bytes — only the bare "B" suffix (not "XB" for some X).
// The "KB"/"MB"/"GB"/"TB" cases above are tried first and win.
multiplier = 1
numPart = s[:len(s)-len("B")]
default:
numPart = s
}
numPart = strings.TrimSpace(numPart)
if numPart == "" {
return 0, fmt.Errorf("log size %q: missing numeric part", orig)
}
n, err := strconv.ParseInt(numPart, 10, 64)
if err != nil {
return 0, fmt.Errorf("log size %q: %w", orig, err)
}
if n < 0 {
return 0, fmt.Errorf("log size %q: must be non-negative", orig)
}
return n * multiplier, nil
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Remove the minus sign and supply a positive size, e.g. "100MB".
- Fix the generating script/logic that produced a negative size.
- Clamp or reject negative sizes at config-load time with a clearer error.
Example fix
// before log_max_size = "-100MB" // after log_max_size = "100MB"
Defensive patterns
Strategy: validation
Validate before calling
if strings.HasPrefix(strings.TrimSpace(cfg.LogMaxSize), "-") {
return fmt.Errorf("log_max_size must be non-negative, got %q", cfg.LogMaxSize)
} Try / catch
size, err := daemon.ParseLogSize(s)
if err != nil {
if strings.Contains(err.Error(), "must be non-negative") {
return fmt.Errorf("remove the negative sign from log_max_size")
}
return err
} Prevention
- Never write negative sizes in config.toml.
- If sizes are computed by scripts, assert non-negativity before emitting the config.
- Sanity-check generated configs with a lint/validation step.
When it happens
Trigger: Calling ParseLogSize with "-100MB", "-1", or any value whose numeric part parses negative.
Common situations: A sign typo in config.toml; a subtraction or delta expression accidentally written into the config; a script computing a size that underflowed to a negative number.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- log backups %q: must be >= 1 (got %d)
- tmux: 'session' option is required (name of the tmux session
- config: relay.visibility must be "full", "summary", or "none
- config: at least one [[projects]] entry is required
- config: %s.name is required
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/671b0b58e2f2e7ec.
Report an issue: GitHub.