{"record":{"id":"c9e1b91d96224e1c","repo":"chenhg5/cc-connect","slug":"log-size-empty-value","errorCode":null,"errorMessage":"log size: empty value","messagePattern":"log size: empty value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/logsize.go","lineNumber":23,"sourceCode":"\t\"strconv\"\n\t\"strings\"\n)\n\n// ParseLogSize converts a human-friendly byte size string (e.g. \"10MB\",\n// \"512K\", \"1G\", or a raw byte count) into a byte count. Suffixes are\n// case-insensitive and may be followed by optional whitespace. Both the SI\n// short forms (K, M, G) and the long forms (KB, MB, GB) are accepted and\n// always use the binary (1024-based) multiplier — matching what users see\n// in editor \"file size\" columns and the existing DefaultLogMaxSize comment\n// of \"10 MB\".\n//\n// Returns an error if the input is empty, negative, has an unknown suffix,\n// or cannot be parsed as an integer.\nfunc ParseLogSize(s string) (int64, error) {\n\torig := s\n\ts = strings.TrimSpace(s)\n\tif s == \"\" {\n\t\treturn 0, fmt.Errorf(\"log size: empty value\")\n\t}\n\n\t// Walk from the end of the string. Suffix is one of the documented forms\n\t// (K, KB, M, MB, G, GB, T, TB). Comparison is case-insensitive — the\n\t// long forms are tried first so e.g. \"10MB\" matches \"MB\" rather than\n\t// falling through to the bare \"B\" branch. The numeric part is parsed\n\t// verbatim, so a stray \"10XYZ\" fails loudly rather than silently\n\t// downgrading to a 10-byte log.\n\tupper := strings.ToUpper(s)\n\tvar multiplier int64 = 1\n\tvar numPart string\n\tswitch {\n\tcase strings.HasSuffix(upper, \"TB\"):\n\t\tmultiplier = 1024 * 1024 * 1024 * 1024\n\t\tnumPart = s[:len(s)-len(\"TB\")]\n\tcase strings.HasSuffix(upper, \"T\"):\n\t\tmultiplier = 1024 * 1024 * 1024 * 1024\n\t\tnumPart = s[:len(s)-len(\"T\")]","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/logsize.go#L5-L41","documentation":"ParseLogSize input guard: the log size value is empty after trimming, so no byte size can be derived. Accepted forms are raw byte counts or K/M/G (short or KB/MB/GB, case-insensitive) with binary 1024-based multipliers; empty, negative, or unknown-suffix values are rejected.","triggerScenarios":"Calling ParseLogSize (directly or via resolveLogMaxSize/main) with \"\" or a whitespace-only string such as \"   \".","commonSituations":"Missing config.toml key read as empty string; env var like CC_CONNECT_LOG_SIZE defined but empty (`export CC_CONNECT_LOG_SIZE=`); template rendering leaving a blank value.","solutions":["Set a concrete size value, e.g. \"100MB\" or \"52428800\".","If the value comes from an env var, give it a non-empty value or unset it so the default applies.","Add a default in the config resolution layer for empty input instead of passing it through."],"exampleFix":"// before (shell)\nexport CC_CONNECT_LOG_SIZE=\n// after\nexport CC_CONNECT_LOG_SIZE=100MB","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(cfg.LogMaxSize) == \"\" {\n    return fmt.Errorf(\"log_max_size is required and must be non-empty, e.g. \\\"100MB\\\"\")\n}","typeGuard":null,"tryCatchPattern":"size, err := daemon.ParseLogSize(s)\nif err != nil {\n    if strings.Contains(err.Error(), \"empty value\") {\n        size = defaultLogSize // apply a documented default\n    }\n    return err\n}","preventionTips":["Always give the size key a value in config.toml; remove the key entirely if you want the default.","Guard env vars: treat empty as unset (`[ -n \"$VAR\" ]`).","Validate config at startup with clear field-level messages."],"tags":["config","validation","empty-value"],"backgroundTag":"empty-required-field","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"}