juanfont/headscale · error · ErrBracketsNotIPv6

%w: %q

Error message

%w: %q

What it means

Error "%w: %q" thrown in juanfont/headscale.

Source

Thrown at hscontrol/policy/v2/utils.go:49

//
// Brackets are only accepted around IPv6 addresses, not IPv4, hostnames, or other alias types.
// Bracket stripping reduces both forms to bare "addr:port" or "addr/prefix:port",
// which the normal [strings.LastIndex] of ":" split handles correctly because
// port strings never contain colons.
func splitDestinationAndPort(input string) (string, string, error) {
	// Handle RFC 3986 bracketed IPv6 (e.g. "[::1]:80" or "[fd7a::1]/128:80,443").
	// Strip brackets after validation and fall through to normal parsing.
	if strings.HasPrefix(input, "[") {
		closeBracket := strings.Index(input, "]")
		if closeBracket == -1 {
			return "", "", ErrBracketsNotIPv6
		}

		host := input[1:closeBracket]

		addr, err := netip.ParseAddr(host)
		if err != nil || !addr.Is6() {
			return "", "", fmt.Errorf("%w: %q", ErrBracketsNotIPv6, host)
		}

		rest := input[closeBracket+1:]
		if len(rest) == 0 || (rest[0] != ':' && rest[0] != '/') {
			return "", "", fmt.Errorf("%w: %q", ErrBracketsNotIPv6, input)
		}

		// Strip brackets: "[addr]:port" → "addr:port",
		// "[addr]/prefix:port" → "addr/prefix:port".
		input = host + rest
	}

	// Find the last occurrence of the colon character
	lastColonIndex := strings.LastIndex(input, ":")

	// Check if the colon character is present and not at the beginning or end of the string
	if lastColonIndex == -1 {
		return "", "", ErrInputMissingColon

View on GitHub (pinned to 565fd254d0)

Solutions

  1. Inspect the wrapped error for the underlying cause and correct the failing condition (); retry the operation after fixing the input, configuration, or environment.

Example fix

Inspect the wrapped error for the underlying cause and correct the failing condition (); retry the operation after fixing the input, configuration, or environment.

When it happens

Trigger: Thrown at hscontrol/policy/v2/utils.go:49 when the library encounters an invalid state.

Common situations: Parsing a host:port or port-range value failed on the quoted input. Use the form host:ports with valid port numbers or '*'.


AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15). Data as JSON: /api/errors/8a0f4eb9b2c3e345. Report an issue: GitHub.