{"record":{"id":"f010089bd3601705","repo":"slimtoolkit/slim","slug":"invalid-port-range-in-expose-s-error-s","errorCode":null,"errorMessage":"invalid port range in EXPOSE: %s / error: %s","messagePattern":"invalid port range in EXPOSE: (.+?) / error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/command/clifvparser.go","lineNumber":67,"sourceCode":"\t\treturn \"\"\n\tdefault:\n\t\treturn flag //should validate if it can be a Docker volume name\n\t}\n}\n\n// based on expose opt parsing in Docker\nfunc ParseDockerExposeOpt(values []string) (map[docker.Port]struct{}, error) {\n\texposedPorts := map[docker.Port]struct{}{}\n\n\tfor _, raw := range values {\n\t\tif strings.Contains(raw, \":\") {\n\t\t\treturn nil, fmt.Errorf(\"invalid EXPOSE format: %s\", raw)\n\t\t}\n\n\t\tproto, ports := nat.SplitProtoPort(raw)\n\t\tstartPort, endPort, err := nat.ParsePortRange(ports)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid port range in EXPOSE: %s / error: %s\", raw, err)\n\t\t}\n\n\t\tfor i := startPort; i <= endPort; i++ {\n\t\t\tportInfo, err := nat.NewPort(proto, strconv.FormatUint(i, 10))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\texposedPorts[docker.Port(portInfo)] = struct{}{}\n\t\t}\n\t}\n\treturn exposedPorts, nil\n}\n\nfunc ParsePortBindings(values []string) (map[docker.Port][]docker.PortBinding, error) {\n\tportBindings := map[docker.Port][]docker.PortBinding{}\n\n\tfor _, raw := range values {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/command/clifvparser.go#L49-L85","documentation":"ParseDockerExposeOpt returns 'invalid port range in EXPOSE: %s / error: %s' when nat.ParsePortRange cannot parse the port portion of an EXPOSE value. The port must be a number or a numeric range like '1000-2000'. Non-numeric or out-of-range ports produce this wrapped error including the underlying cause.","triggerScenarios":"Calling ParseDockerExposeOpt with values like 'http', '80-80000', '80-', or other port strings that fail Docker's port-range parsing.","commonSituations":"Using service names instead of numbers (EXPOSE in Dockerfiles accepts names via build, but this parser does not); typos in port ranges; reversed or overflowing range bounds.","solutions":["Replace service names with numeric ports, e.g. 'http' -> '80'.","Ensure ranges are numeric with start <= end and within 0-65535, e.g. '1000-2000'.","Check the wrapped underlying error in the message for the exact parse failure.","Normalize inputs (trim whitespace, remove stray characters) before parsing."],"exampleFix":"// before\nexpose := []string{\"http\"}\n// after\nexpose := []string{\"80\"}","handlingStrategy":"validation","validationCode":"func validPortOrRange(s string) bool {\n    if strings.Contains(s, \"-\") {\n        parts := strings.SplitN(s, \"-\", 2)\n        a, e1 := strconv.Atoi(parts[0]); b, e2 := strconv.Atoi(parts[1])\n        return e1 == nil && e2 == nil && a <= b && a > 0 && b <= 65535\n    }\n    p, err := strconv.Atoi(s)\n    return err == nil && p > 0 && p <= 65535\n}","typeGuard":null,"tryCatchPattern":"ports, err := command.ParseDockerExposeOpt(values)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid port range\") {\n        return fmt.Errorf(\"fix numeric ports/ranges: %w\", err)\n    }\n    return err\n}","preventionTips":["Use numeric ports, never service names, in this parser.","Ensure ranges are numeric, ascending, and within 0-65535.","Trim whitespace and strip stray characters before parsing.","Surface the wrapped underlying error for precise feedback."],"tags":["docker","ports","parsing"],"backgroundTag":"invalid-port-syntax","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}