{"record":{"id":"fb7b9e6e4a911507","repo":"k3s-io/k3s","slug":"invalid-ip-format-s","errorCode":null,"errorMessage":"invalid ip format '%s'","messagePattern":"invalid ip format '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/net.go","lineNumber":184,"sourceCode":"\t\tname = hostname\n\t}\n\n\t// Use lower case hostname to comply with kubernetes constraint:\n\t// https://github.com/kubernetes/kubernetes/issues/71140\n\tname = strings.ToLower(name)\n\n\treturn name, ips, nil\n}\n\n// ParseStringSliceToIPs converts slice of strings that in turn can be lists of comma separated unparsed IP addresses\n// into a single slice of net.IP, it returns error if at any point parsing failed\nfunc ParseStringSliceToIPs(s []string) ([]net.IP, error) {\n\tvar ips []net.IP\n\tfor _, unparsedIP := range s {\n\t\tfor _, v := range strings.Split(unparsedIP, \",\") {\n\t\t\tip := net.ParseIP(v)\n\t\t\tif ip == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid ip format '%s'\", v)\n\t\t\t}\n\t\t\tips = append(ips, ip)\n\t\t}\n\t}\n\n\treturn ips, nil\n}\n\n// GetFirstValidIPString returns the first valid address from a list of IP address strings,\n// without preference for IP family. If no address are found, an empty string is returned.\nfunc GetFirstValidIPString(s []string) string {\n\tfor _, unparsedIP := range s {\n\t\tfor _, v := range strings.Split(unparsedIP, \",\") {\n\t\t\tif ip := net.ParseIP(v); ip != nil {\n\t\t\t\treturn v\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/k3s-io/k3s/blob/6ba341e396edc16b8dcae978a7c5e3ac7ee5606e/pkg/util/net.go#L166-L202","documentation":"Inside ParseStringSliceToIPs each input string is split on ',' and every token goes through net.ParseIP; the first token that returns nil (not parseable as IPv4 or IPv6) produces this error naming the offending token. It is also the underlying error surfaced by the 'invalid node-ip' wrapper when parsing node IPs.","triggerScenarios":"Calling util.ParseStringSliceToIPs with a typo'd address, an empty token (from 'a,,b' or a trailing comma), a CIDR, or a hostname in the list.","commonSituations":"Helm/CLI templating emitting empty values (',,'); env var interpolation leaving placeholders like '<nodeIP>'; users pasting '10.0.0.1/24' or a DNS name into an IP-only field.","solutions":["Read the token quoted in the message - it is exactly what failed to parse","Strip empties and whitespace before parsing: strings.TrimSpace on each token, drop zero-length items","Allow only literal IPs in whatever field feeds this API; validate in your config layer with net.ParseIP"],"exampleFix":"// before\nips, err := util.ParseStringSliceToIPs(cfg.NodeIPs)\n// after\ncleaned := []string{}\nfor _, s := range cfg.NodeIPs {\n\tfor _, tok := range strings.Split(s, \",\") {\n\t\tif tok = strings.TrimSpace(tok); tok != \"\" {\n\t\t\tcleaned = append(cleaned, tok)\n\t\t}\n\t}\n}\nips, err := util.ParseStringSliceToIPs(cleaned)","handlingStrategy":"validation","validationCode":"func CleanIPList(in []string) ([]string, error) {\n\tout := []string{}\n\tfor _, s := range in {\n\t\tfor _, tok := range strings.Split(s, \",\") {\n\t\t\ttok = strings.TrimSpace(tok)\n\t\t\tif tok == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif net.ParseIP(tok) == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid ip format '%s'\", tok)\n\t\t\t}\n\t\t\tout = append(out, tok)\n\t\t}\n\t}\n\treturn out, nil\n}","typeGuard":"func isLiteralIP(s string) bool { return net.ParseIP(s) != nil }","tryCatchPattern":"ips, err := util.ParseStringSliceToIPs(list)\nif err != nil {\n\tif strings.Contains(err.Error(), \"invalid ip format\") {\n\t\t// the quoted token in the message is the exact bad value; fix the source list\n\t}\n\treturn nil, err\n}","preventionTips":["Trim and drop empty tokens before parsing comma-separated IP lists","Validate user-facing IP inputs with net.ParseIP at the boundary","Beware templating that renders empty optional values as '' or ','","Prefer structured config (YAML arrays) over comma-joined strings when possible"],"tags":["go","network","ip","parsing","configuration"],"backgroundTag":null,"analyzedSha":"6ba341e396edc16b8dcae978a7c5e3ac7ee5606e","analyzedAt":"2026-08-15T16:27:54.286Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}