{"record":{"id":"c886bfd3a531f813","repo":"juicedata/juicefs","slug":"invalid-unit","errorCode":null,"errorMessage":"invalid unit","messagePattern":"invalid unit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/utils/humanize.go","lineNumber":58,"sourceCode":"\tval, err := strconv.ParseFloat(s, 64)\n\tif err == nil {\n\t\tvar shift int\n\t\tswitch unit {\n\t\tcase 'B':\n\t\tcase 'k', 'K':\n\t\t\tshift = 10\n\t\tcase 'm', 'M':\n\t\t\tshift = 20\n\t\tcase 'g', 'G':\n\t\t\tshift = 30\n\t\tcase 't', 'T':\n\t\t\tshift = 40\n\t\tcase 'p', 'P':\n\t\t\tshift = 50\n\t\tcase 'e', 'E':\n\t\t\tshift = 60\n\t\tdefault:\n\t\t\terr = errors.New(\"invalid unit\")\n\t\t}\n\t\tval *= float64(uint64(1) << shift)\n\t}\n\tif err != nil {\n\t\tlogger.Fatalf(\"Invalid value \\\"%s\\\" for \\\"%s\\\": %s\", str, key, err)\n\t}\n\treturn uint64(val)\n}\n\nfunc ParseMbps(ctx *cli.Context, key string) int64 {\n\tstr := ctx.String(key)\n\tif len(str) == 0 {\n\t\treturn 0\n\t}\n\n\treturn ParseMbpsStr(key, str)\n}\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/utils/humanize.go#L40-L76","documentation":"ParseBytesStr parses a human-readable byte size string (e.g. \"10G\", \"512M\") into a numeric value. It throws \"invalid unit\" when the string's trailing unit character is not one of the recognized SI/binary unit letters (k/K, m/M, g/G, t/T, p/P, e/E). After the error, the code calls logger.Fatalf, so the process terminates — the error is effectively fatal, not returnable.","triggerScenarios":"Calling utils.ParseBytes or ParseBytesStr with a string whose unit suffix is unrecognized: empty unit after a number where one is required, misspelled units (\"10gi\", \"10kb\" lowercase double-letter forms are not supported — only the first letter is examined), non-unit trailing characters (\"10x\", \"10 \"), or purely alphabetic junk passed as a size flag/config value.","commonSituations":"Users pass --block-size, --buffer-size, or cache-size flags with units the parser doesn't understand (\"1.5GiB\", \"10 MB\", \"10kb\") in mount or format commands; config files or environment-derived strings carry localized unit spellings; a YAML/JSON config field holds a plain number with an accidental suffix.","solutions":["Use a supported single-letter unit: B (or none), k/K, m/M, g/G, t/T, p/P, e/E, e.g. \"10G\" instead of \"10GiB\".","Check for trailing whitespace or stray characters in the value and trim them.","Express fractional or precise sizes in the largest supported unit (e.g. 1536M instead of 1.5G).","If the value comes from a config file, print it before parsing to confirm what string is actually being fed in."],"exampleFix":"// before\nParseBytes(\"--block-size\", \"4MiB\")\n// after\nParseBytes(\"--block-size\", \"4M\")","handlingStrategy":"validation","validationCode":"var validUnits = \"kmgtpeKMGTPE\"\nfunc validByteSize(s string) bool {\n\ts = strings.TrimSpace(s)\n\tif s == \"\" { return false }\n\tbody, unit := s[:len(s)-1], s[len(s)-1]\n\tif !strings.ContainsAny(string(unit), validUnits) { return false }\n\t_, err := strconv.ParseFloat(body, 64)\n\treturn err == nil\n}\n// call ParseBytes only if validByteSize(value)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on single-letter units (K, M, G, T) in all configs and docs","Trim whitespace from size strings before parsing","Add a config-level schema check that validates size fields against the accepted unit set","Remember only the last character is the unit — never write GiB/MiB/kbps style suffixes"],"tags":["config","parsing","cli","units"],"backgroundTag":"invalid-config-value","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}