{"record":{"id":"671b0b58e2f2e7ec","repo":"chenhg5/cc-connect","slug":"log-size-q-must-be-non-negative","errorCode":null,"errorMessage":"log size %q: must be non-negative","messagePattern":"log size %q: must be non-negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/logsize.go","lineNumber":79,"sourceCode":"\t\t// Explicit bytes — only the bare \"B\" suffix (not \"XB\" for some X).\n\t\t// The \"KB\"/\"MB\"/\"GB\"/\"TB\" cases above are tried first and win.\n\t\tmultiplier = 1\n\t\tnumPart = s[:len(s)-len(\"B\")]\n\tdefault:\n\t\tnumPart = s\n\t}\n\n\tnumPart = strings.TrimSpace(numPart)\n\tif numPart == \"\" {\n\t\treturn 0, fmt.Errorf(\"log size %q: missing numeric part\", orig)\n\t}\n\n\tn, err := strconv.ParseInt(numPart, 10, 64)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"log size %q: %w\", orig, err)\n\t}\n\tif n < 0 {\n\t\treturn 0, fmt.Errorf(\"log size %q: must be non-negative\", orig)\n\t}\n\n\treturn n * multiplier, nil\n}\n","sourceCodeStart":61,"sourceCodeEnd":84,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/logsize.go#L61-L84","documentation":"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.","triggerScenarios":"Calling ParseLogSize with \"-100MB\", \"-1\", or any value whose numeric part parses negative.","commonSituations":"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.","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."],"exampleFix":"// before\nlog_max_size = \"-100MB\"\n// after\nlog_max_size = \"100MB\"","handlingStrategy":"validation","validationCode":"if strings.HasPrefix(strings.TrimSpace(cfg.LogMaxSize), \"-\") {\n    return fmt.Errorf(\"log_max_size must be non-negative, got %q\", cfg.LogMaxSize)\n}","typeGuard":null,"tryCatchPattern":"size, err := daemon.ParseLogSize(s)\nif err != nil {\n    if strings.Contains(err.Error(), \"must be non-negative\") {\n        return fmt.Errorf(\"remove the negative sign from log_max_size\")\n    }\n    return err\n}","preventionTips":["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."],"tags":["config","validation","range-check"],"backgroundTag":"value-out-of-range","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}