ginuerzh/gost · error
must specify at least one port
Error message
must specify at least one port
What it means
ParsePortSet rejects an empty string because a PortSet with no ports would never match anything and is almost certainly a configuration mistake. Permissions strings are comma-separated, and an empty segment means no port was specified at all.
Source
Thrown at permissions.go:76
return nil, fmt.Errorf("invalid range: %s", s)
}
}
// Contains checks whether the value is within this range.
func (ir *PortRange) Contains(value int) bool {
return value >= ir.Min && value <= ir.Max
}
// PortSet is a set of PortRange
type PortSet []PortRange
// ParsePortSet parses the s to a PortSet.
// The s shoud be a comma separated string.
func ParsePortSet(s string) (*PortSet, error) {
ps := &PortSet{}
if s == "" {
return nil, errors.New("must specify at least one port")
}
ranges := strings.Split(s, ",")
for _, r := range ranges {
portRange, err := ParsePortRange(r)
if err != nil {
return nil, err
}
*ps = append(*ps, *portRange)
}
return ps, nil
}
// Contains checks whether the value is within this port set.View on GitHub (pinned to a33fdbf4c9)
Solutions
- Provide a non-empty comma-separated port list, e.g. "80,443" or "8000-9000"
- Check the config file/env var that feeds the permissions string for missing or blank values
- If an empty set is legitimate in your app, skip calling ParsePortSet when the input is empty
Example fix
// before
ps, err := permissions.ParsePortSet(portStr) // portStr == ""
// after
var ps *permissions.PortSet
if portStr != "" {
ps, err = permissions.ParsePortSet(portStr)
} Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(portStr) == "" {
return errors.New("ports must be a non-empty comma-separated list")
}
ps, err := permissions.ParsePortSet(portStr) Try / catch
if err != nil {
return fmt.Errorf("invalid port permissions %q: %w", portStr, err)
} Prevention
- Validate config files at startup with required non-empty fields
- Avoid defaulting env vars to empty strings for required lists
- Use a linter/schema validator for permission configs
When it happens
Trigger: Calling ParsePortSet("") directly, or ParsePermissions with a port field that is the empty string (e.g. missing or blank in a config file).
Common situations: Blank 'ports' entry in a YAML/JSON config, an environment variable that is unset and defaults to empty string, or template rendering producing an empty value.
Related errors
- ErrInvalidNode
- cannot be empty
- invalid port: %s
- invalid range: %s
- action list must look like connect,bind given: %s
AI-assisted analysis of ginuerzh/gost@a33fdbf4c9 (2026-09-02).
Data as JSON: /api/errors/70670e90d00a4e42.
Report an issue: GitHub.