{"record":{"id":"70670e90d00a4e42","repo":"ginuerzh/gost","slug":"must-specify-at-least-one-port","errorCode":null,"errorMessage":"must specify at least one port","messagePattern":"must specify at least one port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"permissions.go","lineNumber":76,"sourceCode":"\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\")\n\t}\n\n\tranges := strings.Split(s, \",\")\n\n\tfor _, r := range ranges {\n\t\tportRange, err := ParsePortRange(r)\n\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\t*ps = append(*ps, *portRange)\n\t}\n\n\treturn ps, nil\n}\n\n// Contains checks whether the value is within this port set.","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/permissions.go#L58-L94","documentation":"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.","triggerScenarios":"Calling ParsePortSet(\"\") directly, or ParsePermissions with a port field that is the empty string (e.g. missing or blank in a config file).","commonSituations":"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.","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"],"exampleFix":"// before\nps, err := permissions.ParsePortSet(portStr) // portStr == \"\"\n// after\nvar ps *permissions.PortSet\nif portStr != \"\" {\n    ps, err = permissions.ParsePortSet(portStr)\n}","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(portStr) == \"\" {\n    return errors.New(\"ports must be a non-empty comma-separated list\")\n}\nps, err := permissions.ParsePortSet(portStr)","typeGuard":null,"tryCatchPattern":"if err != nil {\n    return fmt.Errorf(\"invalid port permissions %q: %w\", portStr, err)\n}","preventionTips":["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"],"tags":["config","ports","validation"],"backgroundTag":"missing-or-empty-config-value","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}