XTLS/Xray-core · error

unsupported unit:

Error message

unsupported unit: 

What it means

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.

Source

Thrown at infra/conf/transport_method.go:736

	val, err := strconv.ParseFloat(numStr, 64)
	if err != nil {
		return 0, err
	}

	mul := uint64(1)
	switch unit {
	case "", "b", "bps":
		mul = Byte
	case "k", "kb", "kbps":
		mul = Kilobyte
	case "m", "mb", "mbps":
		mul = Megabyte
	case "g", "gb", "gbps":
		mul = Gigabyte
	case "t", "tb", "tbps":
		mul = Terabyte
	default:
		return 0, errors.New("unsupported unit: " + unit)
	}

	return uint64(val*float64(mul)) / 8, nil
}

type UdpHop struct {
	PortList PortList   `json:"ports"`
	Interval Int32Range `json:"interval"`
}

type Masquerade struct {
	Type string `json:"type"`

	Dir string `json:"dir"`

	Url         string `json:"url"`
	RewriteHost bool   `json:"rewriteHost"`
	Insecure    bool   `json:"insecure"`

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Use a supported lowercase unit, e.g. "100 mbps" or "5 mb".
  2. Strip whitespace around the number/unit before writing the config.
  3. If you need bits-per-second semantics remember the value is divided by 8 — supply e.g. mbps and the parser converts.

Example fix

// before
"up": "100 MBps", "down": "200 MBPS"
// after
"up": "100 mbps", "down": "200 mbps"
Defensive patterns

Strategy: validation

Validate before calling

var bwRe = regexp.MustCompile(`^\s*([0-9]+(?:\.[0-9]+)?)\s*([a-z]*)\s*$`)
validUnits := 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}
func validBandwidth(s string) bool {
    m := bwRe.FindStringSubmatch(strings.ToLower(s))
    return m != nil && validUnits[m[2]]
}

Prevention

When it happens

Trigger: 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".

Common situations: Configs authored from Hysteria's own docs which may use different casing, or copy-paste introducing whitespace/typographical units.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/ff710ba524168641. Report an issue: GitHub.