{"record":{"id":"a1374e5101908174","repo":"ginuerzh/gost","slug":"invalid-range-s","errorCode":null,"errorMessage":"invalid range: %s","messagePattern":"invalid range: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"permissions.go","lineNumber":58,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"invalid port: %s\", s)\n\t\t}\n\t\treturn &PortRange{Min: port, Max: port}, nil\n\tcase 2:\n\t\tmin, err := strconv.Atoi(minmax[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tmax, err := strconv.Atoi(minmax[1])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\trealmin := maxint(0, minint(min, max))\n\t\trealmax := minint(65535, maxint(min, max))\n\n\t\treturn &PortRange{Min: realmin, Max: realmax}, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid range: %s\", s)\n\t}\n}\n\n// Contains checks whether the value is within this range.\nfunc (ir *PortRange) Contains(value int) bool {\n\treturn value >= ir.Min && value <= ir.Max\n}\n\n// PortSet is a set of PortRange\ntype PortSet []PortRange\n\n// ParsePortSet parses the s to a PortSet.\n// The s shoud be a comma separated string.\nfunc ParsePortSet(s string) (*PortSet, error) {\n\tps := &PortSet{}\n\n\tif s == \"\" {\n\t\treturn nil, errors.New(\"must specify at least one port\")","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/permissions.go#L40-L76","documentation":"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\".","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nports = \"1-100-\"\n// after\nports = \"1-100\"","handlingStrategy":"validation","validationCode":"var portRe = regexp.MustCompile(`^\\d+(-\\d+)?$`)\nif !portRe.MatchString(spec) {\n    return fmt.Errorf(\"port spec must be N or N-M, got %q\", spec)\n}","typeGuard":null,"tryCatchPattern":"pr, err := ParsePortRange(spec)\nif err != nil {\n    return fmt.Errorf(\"malformed range %q: %w\", spec, err)\n}","preventionTips":["Trim whitespace and strip stray dashes before parsing","Enforce a strict regex on port specs","Add config validation tests"],"tags":["validation","ports","permissions"],"backgroundTag":"invalid-port-range","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}