{"record":{"id":"4fec6ea78125baa4","repo":"muesli/duf","slug":"prefix-s-not-allowed-valid-prefixes-are-k-m","errorCode":null,"errorMessage":"prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E","messagePattern":"prefix '(.+?)' not allowed, valid prefixes are K, M, G, T, P, E","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"table.go","lineNumber":531,"sourceCode":"\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\":\n\t\t\tsize = num << 50\n\t\tcase \"E\":\n\t\t\tsize = num << 60\n\t\tdefault:\n\t\t\terr = fmt.Errorf(\"prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E\", prefix)\n\t\t\treturn\n\t\t}\n\t} else {\n\t\tsize = num\n\t}\n\treturn\n}\n\n// stringToColumn converts a column name to its index.\nfunc stringToColumn(s string) (int, error) {\n\ts = strings.ToLower(s)\n\n\tfor i, v := range columns {\n\t\tif v.ID == s {\n\t\t\treturn i + 1, nil\n\t\t}\n\t}\n","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/muesli/duf/blob/4636deb4a7b707a9f04c602db033f9837e50b3f6/table.go#L513-L549","documentation":"After the numeric part of a size string parses, stringToSize switches on the SI prefix. Although the regex only admits K/M/G/T/P/E or empty, if the prefix somehow reaches the default case the function returns \"prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E\". This is a defensive guard listing the valid multipliers.","triggerScenarios":"stringToSize receives a size token whose prefix fails the shift-based switch — practically unreachable via the public regex, but reachable if the regex is relaxed/modified or the function is refactored to accept arbitrary prefixes.","commonSituations":"Hitting this after code changes that loosen the validation regex (e.g. allowing lowercase or IEC prefixes) without updating the switch; users seeing it from custom builds.","solutions":["Use one of the supported uppercase prefixes: K, M, G, T, P, E.","If the validation regex was modified, restore ^\\d+([KMGTPE]?)$ or add matching switch cases.","Convert IEC units (KiB/MiB) to the supported SI prefixes."],"exampleFix":"// before\ncase \"k\": size = num << 10 // lowercase unsupported upstream\n// after\ncase \"K\": size = num << 10","handlingStrategy":"validation","validationCode":"validPrefixes := map[string]bool{\"K\": true, \"M\": true, \"G\": true, \"T\": true, \"P\": true, \"E\": true, \"\": true}\nif !validPrefixes[prefix] { /* reject before calling */ }","typeGuard":null,"tryCatchPattern":"size, err := stringToSize(input)\nif err != nil {\n\treturn fmt.Errorf(\"bad prefix in %q: %w\", input, err)\n}","preventionTips":["Stick to the uppercase prefixes K M G T P E.","If you modify the validation regex, update the prefix switch in step.","Convert IEC units (KiB) to SI equivalents before passing."],"tags":["go","parsing","si-units"],"backgroundTag":"invalid-enum-value","analyzedSha":"4636deb4a7b707a9f04c602db033f9837e50b3f6","analyzedAt":"2026-09-06T02:31:58.576Z","contentChangedAt":"2026-09-06T02:31:58.576Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}