{"record":{"id":"287da63b312d21d8","repo":"micro/go-micro","slug":"erripnotfound","errorCode":"ErrIPNotFound","errorMessage":"no IP address found, and explicit IP not provided","messagePattern":"no IP address found, and explicit IP not provided","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/addr/addr.go","lineNumber":12,"sourceCode":"// addr provides functions to retrieve local IP addresses from device interfaces.\npackage addr\n\nimport (\n\t\"net\"\n\n\t\"github.com/pkg/errors\"\n)\n\nvar (\n\t// ErrIPNotFound no IP address found, and explicit IP not provided.\n\tErrIPNotFound = errors.New(\"no IP address found, and explicit IP not provided\")\n)\n\n// IsLocal checks whether an IP belongs to one of the device's interfaces.\nfunc IsLocal(addr string) bool {\n\t// Extract the host\n\thost, _, err := net.SplitHostPort(addr)\n\tif err == nil {\n\t\taddr = host\n\t}\n\n\tif addr == \"localhost\" {\n\t\treturn true\n\t}\n\n\t// Check against all local ips\n\tfor _, ip := range IPs() {\n\t\tif addr == ip {\n\t\t\treturn true","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/addr/addr.go#L1-L30","documentation":"ErrIPNotFound is the exported sentinel in internal/util/addr returned by findIP when it cannot determine any usable local IP address — either no interface yields a usable address or the explicitly requested IP is not present on the host. Callers compare with errors.Is to detect this condition.","triggerScenarios":"Calling code that resolves the host IP (findIP, or utilities like ExtractHostPort/IsLocal paths that need an address) on a machine with no non-loopback interfaces, or requesting an explicit IP that is not assigned to any device interface.","commonSituations":"Running in minimal containers (scratch/distroless) missing net tools/interfaces; VMs or sandboxes with only loopback up; specifying an explicit IP env/config value that doesn't exist on the host; Docker/Kubernetes pods with unusual network setups.","solutions":["Ensure at least one network interface has a valid non-loopback IPv4/IPv6 address (check `ip addr` / `ifconfig`).","If an explicit IP is configured, correct it to an address actually assigned to the host.","In containers, verify the network namespace has eth0 configured (e.g. proper Docker network or CNI setup).","Handle the sentinel with errors.Is(err, addr.ErrIPNotFound) and fall back to a configured advertise address."],"exampleFix":"// before\nip, err := addr.FindIP() // panics path: no interface match\n\n// after\nip, err := addr.FindIP()\nif errors.Is(err, addr.ErrIPNotFound) {\n\tip = net.ParseIP(cfg.AdvertiseAddress) // explicit fallback\n}","handlingStrategy":"fallback","validationCode":"addrs, _ := net.InterfaceAddrs()\nhasUsable := false\nfor _, a := range addrs {\n\tif ipn, ok := a.(*net.IPNet); ok && !ipn.IP.IsLoopback() && ipn.IP.To4() != nil {\n\t\thasUsable = true\n\t}\n}\nif !hasUsable {\n\tlog.Warn(\"no non-loopback IP; set explicit advertise address\")\n}","typeGuard":"func isIPNotFound(err error) bool {\n\treturn errors.Is(err, addr.ErrIPNotFound)\n}","tryCatchPattern":"ip, err := addr.FindIP()\nif err != nil {\n\tif errors.Is(err, addr.ErrIPNotFound) {\n\t\tip = net.ParseIP(os.Getenv(\"ADVERTISE_IP\"))\n\t}\n\tif ip == nil {\n\t\treturn fmt.Errorf(\"cannot determine host IP: %w\", err)\n\t}\n}","preventionTips":["Set an explicit advertise/bind IP via config or env in containers and minimal VMs.","Verify network interfaces exist before deploying to scratch/distroless images.","In Kubernetes, prefer the pod IP from the DOWNWARD_API over host discovery.","Compare errors with errors.Is(err, addr.ErrIPNotFound) instead of string matching."],"tags":["network","ip-address","sentinel-error","environment"],"backgroundTag":"ip-not-found","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}