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

  1. Remove the minus sign and supply a positive size, e.g. "100MB".
  2. Fix the generating script/logic that produced a negative size.
  3. 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

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/671b0b58e2f2e7ec. Report an issue: GitHub.