{"record":{"id":"ff710ba524168641","repo":"XTLS/Xray-core","slug":"unsupported-unit","errorCode":null,"errorMessage":"unsupported unit: ","messagePattern":"unsupported unit: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/transport_method.go","lineNumber":736,"sourceCode":"\tval, err := strconv.ParseFloat(numStr, 64)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\tmul := uint64(1)\n\tswitch unit {\n\tcase \"\", \"b\", \"bps\":\n\t\tmul = Byte\n\tcase \"k\", \"kb\", \"kbps\":\n\t\tmul = Kilobyte\n\tcase \"m\", \"mb\", \"mbps\":\n\t\tmul = Megabyte\n\tcase \"g\", \"gb\", \"gbps\":\n\t\tmul = Gigabyte\n\tcase \"t\", \"tb\", \"tbps\":\n\t\tmul = Terabyte\n\tdefault:\n\t\treturn 0, errors.New(\"unsupported unit: \" + unit)\n\t}\n\n\treturn uint64(val*float64(mul)) / 8, nil\n}\n\ntype UdpHop struct {\n\tPortList PortList   `json:\"ports\"`\n\tInterval Int32Range `json:\"interval\"`\n}\n\ntype Masquerade struct {\n\tType string `json:\"type\"`\n\n\tDir string `json:\"dir\"`\n\n\tUrl         string `json:\"url\"`\n\tRewriteHost bool   `json:\"rewriteHost\"`\n\tInsecure    bool   `json:\"insecure\"`","sourceCodeStart":718,"sourceCodeEnd":754,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/transport_method.go#L718-L754","documentation":"Thrown by the bandwidth string parser (used by HysteriaConfig's up/down fields) when the unit suffix after the numeric part is not one of the supported set: '', b, bps, k, kb, kbps, m, mb, mbps, g, gb, gbps, t, tb, tbps. The parser multiplies the value by the unit and divides by 8 to return bits-per-second as bytes-per-second.","triggerScenarios":"Writing \"up\": \"100 Mbps \" with a trailing space or uppercase \"MBPS\" (the switch is case-sensitive), or using an unsupported suffix like \"100 MiB\" or \"1e3\".","commonSituations":"Configs authored from Hysteria's own docs which may use different casing, or copy-paste introducing whitespace/typographical units.","solutions":["Use a supported lowercase unit, e.g. \"100 mbps\" or \"5 mb\".","Strip whitespace around the number/unit before writing the config.","If you need bits-per-second semantics remember the value is divided by 8 — supply e.g. mbps and the parser converts."],"exampleFix":"// before\n\"up\": \"100 MBps\", \"down\": \"200 MBPS\"\n// after\n\"up\": \"100 mbps\", \"down\": \"200 mbps\"","handlingStrategy":"validation","validationCode":"var bwRe = regexp.MustCompile(`^\\s*([0-9]+(?:\\.[0-9]+)?)\\s*([a-z]*)\\s*$`)\nvalidUnits := map[string]bool{\"\": true, \"b\": true, \"bps\": true, \"k\": true, \"kb\": true, \"kbps\": true, \"m\": true, \"mb\": true, \"mbps\": true, \"g\": true, \"gb\": true, \"gbps\": true, \"t\": true, \"tb\": true, \"tbps\": true}\nfunc validBandwidth(s string) bool {\n    m := bwRe.FindStringSubmatch(strings.ToLower(s))\n    return m != nil && validUnits[m[2]]\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize bandwidth strings to lowercase and strip whitespace before writing configs.","Restrict the input UI to a dropdown of supported units."],"tags":["config","hysteria","bandwidth","units","validation","go"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}