caddyserver/caddy · error

invalid end port: %v

Error message

invalid end port: %v

What it means

Same parsing step as the start-port error, but for the end port of a range: after strings.Cut on '-', the 'after' part must parse as uint16. A single port '8080' sets after = before, so the same constraints apply; failures here are reported with this message.

Source

Thrown at listeners.go:359

			Host:    host,
		}, nil
	}
	var start, end uint64
	if port == "" {
		start = uint64(defaultPort)
		end = uint64(defaultPort)
	} else {
		before, after, found := strings.Cut(port, "-")
		if !found {
			after = before
		}
		start, err = strconv.ParseUint(before, 10, 16)
		if err != nil {
			return NetworkAddress{}, fmt.Errorf("invalid start port: %v", err)
		}
		end, err = strconv.ParseUint(after, 10, 16)
		if err != nil {
			return NetworkAddress{}, fmt.Errorf("invalid end port: %v", err)
		}
		if end < start {
			return NetworkAddress{}, fmt.Errorf("end port must not be less than start port")
		}
		if (end - start) > maxPortSpan {
			return NetworkAddress{}, fmt.Errorf("port range exceeds %d ports", maxPortSpan)
		}
	}
	return NetworkAddress{
		Network:   network,
		Host:      host,
		StartPort: uint(start),
		EndPort:   uint(end),
	}, nil
}

// SplitNetworkAddress splits a into its network, host, and port components.
// Note that port may be a port range (:X-Y), or omitted for unix sockets.

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Make the end port a plain integer within 0-65535: ':8080-8090'.
  2. Remove whitespace and stray characters around the hyphen.
  3. For IPv6, wrap the host in brackets: '[::1]:8080-8090' so the port split is unambiguous.

Example fix

// before
caddy.ParseNetworkAddress(":8080-809O") // letter O
// after
caddy.ParseNetworkAddress(":8080-8090")
Defensive patterns

Strategy: validation

Validate before calling

func validPortRange(s string) bool {
    before, after, found := strings.Cut(s, "-")
    if !found { after = before }
    for _, p := range []string{before, after} {
        n, err := strconv.ParseUint(p, 10, 16)
        if err != nil { return false }
        _ = n
    }
    return true
}

Prevention

When it happens

Trigger: Ranges like ':8080-https', ':80-99999', ':80-90a0', ':80-' (empty end), or ':80- 90' with whitespace. Any non-numeric or >65535 end port.

Common situations: Typing a range with a service name at the end, trailing whitespace from templating, or hyphens inside IPv6 literals confusing the split.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/2ea2de45ac24fb14. Report an issue: GitHub.