ginuerzh/gost · error
invalid range: %s
Error message
invalid range: %s
What it means
ParsePortRange splits the spec on '-' and expects 1 or 2 parts. Any other number of dash-separated parts (e.g. "1-2-3" or an empty/malformed spec) hits the default branch and returns "invalid range: %s".
Source
Thrown at permissions.go:58
return nil, fmt.Errorf("invalid port: %s", s)
}
return &PortRange{Min: port, Max: port}, nil
case 2:
min, err := strconv.Atoi(minmax[0])
if err != nil {
return nil, err
}
max, err := strconv.Atoi(minmax[1])
if err != nil {
return nil, err
}
realmin := maxint(0, minint(min, max))
realmax := minint(65535, maxint(min, max))
return &PortRange{Min: realmin, Max: realmax}, nil
default:
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")View on GitHub (pinned to a33fdbf4c9)
Solutions
- Fix the port spec to be a single port ("8080") or a two-part range ("1000-2000").
- Trim whitespace and remove stray dashes before parsing.
- Add a regex pre-validation (e.g. ^\d+(-\d+)?$) in your config loader before calling ParsePortSet.
Example fix
// before ports = "1-100-" // after ports = "1-100"
Defensive patterns
Strategy: validation
Validate before calling
var portRe = regexp.MustCompile(`^\d+(-\d+)?$`)
if !portRe.MatchString(spec) {
return fmt.Errorf("port spec must be N or N-M, got %q", spec)
} Try / catch
pr, err := ParsePortRange(spec)
if err != nil {
return fmt.Errorf("malformed range %q: %w", spec, err)
} Prevention
- Trim whitespace and strip stray dashes before parsing
- Enforce a strict regex on port specs
- Add config validation tests
When it happens
Trigger: Calling ParsePortRange with a string like "1000-2000-3000", "--", or otherwise producing !=1 and !=2 segments after splitting on "-"; also via ParsePortSet with such an element.
Common situations: Copy-paste errors in permission strings (double dashes, trailing dash like "1-100-"); CIDR-style notation mistakenly used for ports ("1-65535/16"); locale or whitespace issues creating extra segments.
Related errors
- invalid port: %s
- must specify at least one port
- action list must look like connect,bind given: %s
- ErrInvalidNode
- cannot be empty
AI-assisted analysis of ginuerzh/gost@a33fdbf4c9 (2026-09-02).
Data as JSON: /api/errors/a1374e5101908174.
Report an issue: GitHub.