{"record":{"id":"c884e1cecba70eee","repo":"docker/cli","slug":"ip-address-is-not-correctly-formatted-s","errorCode":null,"errorMessage":"IP address is not correctly formatted: %s","messagePattern":"IP address is not correctly formatted: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/opts.go","lineNumber":192,"sourceCode":"}\n\n// ValidatorFctType defines a validator function that returns a validated string and/or an error.\ntype ValidatorFctType func(val string) (string, error)\n\n// ValidatorFctListType defines a validator function that returns a validated list of string and/or an error\ntype ValidatorFctListType func(val string) ([]string, error)\n\n// ValidateIPAddress validates if the given value is a correctly formatted\n// IP address, and returns the value in normalized form. Leading and trailing\n// whitespace is allowed, but it does not allow IPv6 addresses surrounded by\n// square brackets (\"[::1]\").\n//\n// Refer to [net.ParseIP] for accepted formats.\nfunc ValidateIPAddress(val string) (string, error) {\n\tif ip := net.ParseIP(strings.TrimSpace(val)); ip != nil {\n\t\treturn ip.String(), nil\n\t}\n\treturn \"\", fmt.Errorf(\"IP address is not correctly formatted: %s\", val)\n}\n\n// ValidateMACAddress validates a MAC address.\n//\n// Deprecated: use [net.ParseMAC]. This function will be removed in the next release.\nfunc ValidateMACAddress(val string) (string, error) {\n\t_, err := net.ParseMAC(strings.TrimSpace(val))\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn val, nil\n}\n\n// ValidateDNSSearch validates domain for resolvconf search configuration.\n// A zero length domain is represented by a dot (.).\nfunc ValidateDNSSearch(val string) (string, error) {\n\tif val = strings.Trim(val, \" \"); val == \".\" {\n\t\treturn val, nil","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/opts.go#L174-L210","documentation":"Returned by ValidateIPAddress (opts/opts.go:192) when net.ParseIP cannot parse the (trimmed) input as an IPv4 or IPv6 address. ValidateIPAddress returns the normalized canonical form on success and is used as a ListOpts validator and by ValidateExtraHost. It explicitly rejects bracketed IPv6 forms like `[::1]` (callers must strip brackets first).","triggerScenarios":"Calling ValidateIPAddress with a non-IP string: a hostname, a truncated address (`127.0.0`), an out-of-range octet (`999.0.0.1`), or `[::1]` with brackets intact. Also fires indirectly wherever this is a validator (e.g. --ip / --ip6-style lists if wired up).","commonSituations":"Passing a DNS name where an IP is required, partial IPv6, or carrying brackets from a copy-pasted URL.","solutions":["Provide a full IPv4 (127.0.0.1) or IPv6 (::1) literal.","Strip surrounding square brackets before calling: input `[::1]` becomes `::1`.","Resolve hostnames to IPs yourself first; this function does not do DNS.","Trim leading/trailing whitespace (the function trims internally, but confirm no other stray characters)."],"exampleFix":"// before\nv, err := opts.ValidateIPAddress(\"[::1]\")\n\n// after\nv, err := opts.ValidateIPAddress(\"::1\")","handlingStrategy":"validation","validationCode":"func isValidIP(val string) bool {\n    return net.ParseIP(strings.TrimSpace(strings.Trim(val, \"[]\"))) != nil\n}","typeGuard":"// isIPAddress narrows a string to a valid normalized IP in Go (returns canonical form).\nfunc isIPAddress(val string) (string, bool) {\n    if ip := net.ParseIP(strings.TrimSpace(val)); ip != nil {\n        return ip.String(), true\n    }\n    return \"\", false\n}","tryCatchPattern":"if _, err := opts.ValidateIPAddress(val); err != nil {\n    return fmt.Errorf(\"invalid IP %q: %w\", val, err)\n}","preventionTips":["Resolve DNS to IPs before constructing IP-bearing config.","Strip brackets from IPv6 before validation.","Centralize IP parsing through ValidateIPAddress so errors are consistent."],"tags":["network","docker","ip-address","validation","parse"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}