{"record":{"id":"62b3569f4b601ac0","repo":"lima-vm/lima","slug":"failed-to-parse-cidr-q-w","errorCode":null,"errorMessage":"failed to parse CIDR %#q: %w","messagePattern":"failed to parse CIDR %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/network.go","lineNumber":225,"sourceCode":"\t\t}\n\t\tif intf == \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q requires specifying interface\", mode)\n\t\t}\n\t\tyq := fmt.Sprintf(`.networks.%q = {\"mode\":%q,\"interface\":%q}`, name, mode, intf)\n\t\treturn networkApplyYQ(ctx, yq)\n\tdefault:\n\t\tif gateway == \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q requires specifying gateway\", mode)\n\t\t}\n\t\tif intf != \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q does not support specifying interface\", mode)\n\t\t}\n\t\tif !strings.Contains(gateway, \"/\") {\n\t\t\tgateway += \"/24\"\n\t\t}\n\t\tgwIP, gwMask, err := net.ParseCIDR(gateway)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse CIDR %#q: %w\", gateway, err)\n\t\t}\n\t\tif gwIP.IsUnspecified() || gwIP.IsLoopback() {\n\t\t\treturn fmt.Errorf(\"invalid IP address: %v\", gwIP)\n\t\t}\n\t\tgwMaskStr := \"255.255.255.0\"\n\t\tif gwMask != nil {\n\t\t\tgwMaskStr = net.IP(gwMask.Mask).String()\n\t\t}\n\t\t// TODO: check IP range collision\n\n\t\tyq := fmt.Sprintf(`.networks.%q = {\"mode\":%q,\"gateway\":%q,\"netmask\":%q,\"interface\":%q}`, name, mode, gwIP.String(), gwMaskStr, intf)\n\t\treturn networkApplyYQ(ctx, yq)\n\t}\n}\n\nfunc networkApplyYQ(ctx context.Context, yq string) error {\n\tfilePath, err := networks.ConfigFile()\n\tif err != nil {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/network.go#L207-L243","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a syntactically valid gateway CIDR, e.g. --gateway 192.168.5.1 or --gateway 192.168.5.1/24","Verify the IP parses (e.g. `ipaddr 192.168.5.1` or any CIDR checker) before running the command","Use a prefix length (0-32), not a dotted netmask, in the --gateway value"],"exampleFix":"// before\nlimactl network create mynet --gateway 255.255.255.0\n// after\nlimactl network create mynet --gateway 192.168.5.1/24","handlingStrategy":"validation","validationCode":"gw=\"192.168.104.1/24\"\npython3 -c \"import ipaddress,sys; ipaddress.ip_interface(sys.argv[1])\" \"$gw\" || { echo \"invalid CIDR: $gw\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate gateway strings with an IP/CIDR parser before passing --gateway","Use dotted-quad IPv4 addresses, never hostnames or netmasks","Let the tool append /24 by passing a bare IP if no custom prefix is needed"],"tags":["network","cidr","validation"],"backgroundTag":"invalid-cidr-notation","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}