lima-vm/lima · error

failed to parse CIDR %#q: %w

Error message

failed to parse CIDR %#q: %w

What it means

The --gateway value must be a valid CIDR (an IP with optional /prefix; /24 is appended automatically when the prefix is omitted). net.ParseCIDR failed on the assembled string, so the network entry was not written and the underlying parse error is wrapped in the message.

Source

Thrown at cmd/limactl/network.go:225

		}
		if intf == "" {
			return fmt.Errorf("network mode %#q requires specifying interface", mode)
		}
		yq := fmt.Sprintf(`.networks.%q = {"mode":%q,"interface":%q}`, name, mode, intf)
		return networkApplyYQ(ctx, yq)
	default:
		if gateway == "" {
			return fmt.Errorf("network mode %#q requires specifying gateway", mode)
		}
		if intf != "" {
			return fmt.Errorf("network mode %#q does not support specifying interface", mode)
		}
		if !strings.Contains(gateway, "/") {
			gateway += "/24"
		}
		gwIP, gwMask, err := net.ParseCIDR(gateway)
		if err != nil {
			return fmt.Errorf("failed to parse CIDR %#q: %w", gateway, err)
		}
		if gwIP.IsUnspecified() || gwIP.IsLoopback() {
			return fmt.Errorf("invalid IP address: %v", gwIP)
		}
		gwMaskStr := "255.255.255.0"
		if gwMask != nil {
			gwMaskStr = net.IP(gwMask.Mask).String()
		}
		// TODO: check IP range collision

		yq := fmt.Sprintf(`.networks.%q = {"mode":%q,"gateway":%q,"netmask":%q,"interface":%q}`, name, mode, gwIP.String(), gwMaskStr, intf)
		return networkApplyYQ(ctx, yq)
	}
}

func networkApplyYQ(ctx context.Context, yq string) error {
	filePath, err := networks.ConfigFile()
	if err != nil {

View on GitHub (pinned to dd909d0973)

Solutions

  1. Pass a syntactically valid gateway CIDR, e.g. --gateway 192.168.5.1 or --gateway 192.168.5.1/24
  2. Verify the IP parses (e.g. `ipaddr 192.168.5.1` or any CIDR checker) before running the command
  3. Use a prefix length (0-32), not a dotted netmask, in the --gateway value

Example fix

// before
limactl network create mynet --gateway 255.255.255.0
// after
limactl network create mynet --gateway 192.168.5.1/24
Defensive patterns

Strategy: validation

Validate before calling

gw="192.168.104.1/24"
python3 -c "import ipaddress,sys; ipaddress.ip_interface(sys.argv[1])" "$gw" || { echo "invalid CIDR: $gw" >&2; exit 1; }

Prevention

When it happens

Trigger: Passing --gateway values like `192.168.5.1/33`, `300.1.2.3`, `192.168.5.1/abc`, or a hostname instead of an IP; anything that fails net.ParseCIDR after the automatic /24 append.

Common situations: Typos in the gateway IP; using a DNS name as gateway; copy-pasting a netmask (e.g. 255.255.255.0) into --gateway instead of a prefix length; IPv6 vs IPv4 confusion with malformed input.

Understand the failure class

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/62b3569f4b601ac0. Report an issue: GitHub.