{"record":{"id":"47801e17481e45c6","repo":"muesli/duf","slug":"s-is-not-valid-must-have-integer-with-optional","errorCode":null,"errorMessage":"'%s' is not valid, must have integer with optional SI prefix","messagePattern":"'(.+?)' is not valid, must have integer with optional SI prefix","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"table.go","lineNumber":508,"sourceCode":"\tcase size >= 1<<30:\n\t\tstr = fmt.Sprintf(\"%.1fG\", b/(1<<30))\n\tcase size >= 1<<20:\n\t\tstr = fmt.Sprintf(\"%.1fM\", b/(1<<20))\n\tcase size >= 1<<10:\n\t\tstr = fmt.Sprintf(\"%.1fK\", b/(1<<10))\n\tdefault:\n\t\tstr = fmt.Sprintf(\"%dB\", size)\n\t}\n\n\treturn\n}\n\n// stringToSize transforms an SI size into a number.\nfunc stringToSize(s string) (size uint64, err error) {\n\tregex := regexp.MustCompile(`^(\\d+)([KMGTPE]?)$`)\n\tmatches := regex.FindStringSubmatch(s)\n\tif len(matches) == 0 {\n\t\treturn 0, fmt.Errorf(\"'%s' is not valid, must have integer with optional SI prefix\", s)\n\t}\n\n\tnum, err := strconv.ParseUint(matches[1], 10, 64)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif matches[2] != \"\" {\n\t\tprefix := matches[2]\n\t\tswitch prefix {\n\t\tcase \"K\":\n\t\t\tsize = num << 10\n\t\tcase \"M\":\n\t\t\tsize = num << 20\n\t\tcase \"G\":\n\t\t\tsize = num << 30\n\t\tcase \"T\":\n\t\t\tsize = num << 40\n\t\tcase \"P\":","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/muesli/duf/blob/4636deb4a7b707a9f04c602db033f9837e50b3f6/table.go#L490-L526","documentation":"stringToSize parses an SI size string like \"10G\" into a byte count. The input must match ^\\d+([KMGTPE]?)$; if it does not, the function returns \"'%s' is not valid, must have integer with optional SI prefix\". This validates the shape of threshold size values before applying the prefix multiplier.","triggerScenarios":"Calling stringToSize (directly or via --avail-threshold parsing) with strings like \"10Gi\", \"1.5G\", \"10k\" (lowercase), \"G10\", or an empty string — anything failing the digit-plus-optional-uppercase-prefix regex.","commonSituations":"Users write decimal sizes (1.5G), IEC suffixes (Gi, MiB), lowercase prefixes (10k), or reversed order (G10) in threshold flags.","solutions":["Use the format <integer><optional uppercase SI prefix>, e.g. \"10\", \"10G\", \"2T\".","Convert decimals to whole units (1.5G -> 1536M).","Use uppercase K/M/G/T/P/E; lowercase k is rejected."],"exampleFix":"// before\nstringToSize(\"1.5G\")\n// after\nstringToSize(\"1536M\")","handlingStrategy":"validation","validationCode":"var sizeRe = regexp.MustCompile(`^\\d+([KMGTPE]?)$`)\nfunc validSize(s string) bool { return sizeRe.MatchString(s) }","typeGuard":null,"tryCatchPattern":"size, err := stringToSize(input)\nif err != nil {\n\treturn fmt.Errorf(\"bad size %q: %w\", input, err)\n}","preventionTips":["Format sizes as integer plus optional uppercase SI prefix (10G, 2T).","Convert decimals (1.5G) to whole smaller units (1536M).","Never use lowercase prefixes or IEC suffixes like Gi/MiB."],"tags":["go","parsing","validation","si-units"],"backgroundTag":"invalid-argument-format","analyzedSha":"4636deb4a7b707a9f04c602db033f9837e50b3f6","analyzedAt":"2026-09-06T02:31:58.576Z","contentChangedAt":"2026-09-06T02:31:58.576Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}