fatedier/frp · error
unit not support
Error message
unit not support
What it means
BandwidthQuantity.UnmarshalJSON (pkg/config/types/types.go:80) accepts only strings suffixed with KB or MB (e.g. "1MB", "512KB"); any other unit — or a bare number string — hits the else branch and returns 'unit not support'. Bandwidth values in frp configs are parsed through this type (bandwidthLimit fields).
Source
Thrown at pkg/config/types/types.go:80
func (q *BandwidthQuantity) UnmarshalString(s string) error {
s = strings.TrimSpace(s)
if s == "" {
return nil
}
var (
base int64
f float64
err error
)
if fstr, ok := strings.CutSuffix(s, "MB"); ok {
base = MB
f, err = strconv.ParseFloat(fstr, 64)
} else if fstr, ok := strings.CutSuffix(s, "KB"); ok {
base = KB
f, err = strconv.ParseFloat(fstr, 64)
} else {
return errors.New("unit not support")
}
if err != nil {
return err
}
q.s = s
q.i = int64(f * float64(base))
return nil
}
func (q *BandwidthQuantity) UnmarshalJSON(b []byte) error {
if len(b) == 4 && string(b) == "null" {
return nil
}
var str string
err := json.Unmarshal(b, &str)
if err != nil {View on GitHub (pinned to 6c8a8d0a97)
Solutions
- Express the limit in KB or MB, e.g. "1024KB" or "1MB" (convert 1GB to "1024MB")
- Remove bandwidthLimit when no limit is intended
- Fix casing: suffix must be exactly 'KB' or 'MB'
- Validate bandwidth strings with a ^\d+(\.\d+)?(KB|MB)$ check in your config pipeline
Example fix
# before transport.bandwidthLimit = "100MBps" # or proxies[0].transport.bandwidthLimit = "1GB" # after transport.bandwidthLimit = "100MB" proxies[0].transport.bandwidthLimit = "1024MB"
Defensive patterns
Strategy: validation
Validate before calling
var bandwidthRe = regexp.MustCompile(`^\d+(\.\d+)?(KB|MB)$`)
if !bandwidthRe.MatchString(cfg.Transport.BandwidthLimit) {
return fmt.Errorf("bandwidthLimit %q must end in KB or MB", cfg.Transport.BandwidthLimit)
} Try / catch
if err := json.Unmarshal(data, &cfg); err != nil {
if strings.Contains(err.Error(), "unit not support") {
return fmt.Errorf("bandwidth values must be like \"1MB\" or \"512KB\" (GB/Mbps/bare numbers unsupported)")
}
return err
} Prevention
- Standardize bandwidth config generation on KB/MB suffixes only
- Lint configs with the regex before deploying
- Remember the check is case-sensitive: exactly 'KB'/'MB'
When it happens
Trigger: Setting bandwidthLimit = "1GB", bandwidthLimit = "100", bandwidthLimit = "10mbps", or any value whose suffix is not exactly KB/MB (case-sensitive per CutSuffix), then starting frpc/frps or reloading — config decode fails at that field.
Common situations: Assuming GB or Mbps are accepted because other tools use them; pasting bandwidth numbers without units; casing differences like 'Mb'; upgrading from configs that were never validated strictly.
Related errors
- ErrHealthCheckType
- type is required
- failed to parse JSON: %w
- proxy [%s] is repeated
- xtcp server for [%s] doesn't exist
AI-assisted analysis of fatedier/frp@6c8a8d0a97 (2026-08-15).
Data as JSON: /api/errors/78e3b09ae567f64c.
Report an issue: GitHub.