{"record":{"id":"f734cc95c569d6d6","repo":"CloakHQ/CloakBrowser","slug":"geoip-lookup-failed-for-ip-exc-message","errorCode":null,"errorMessage":"GeoIP lookup failed for {ip}: {exc.Message}","messagePattern":"GeoIP lookup failed for (.+?): (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/CloakBrowser/GeoIp.cs","lineNumber":138,"sourceCode":"            throw new InvalidOperationException(\"GeoIP resolution failed: could not discover the egress IP\");\n        }\n\n        if (dbPath == null)\n            throw new InvalidOperationException(\"GeoIP resolution failed: GeoIP database is unavailable\");\n\n        try\n        {\n            using var reader = new DatabaseReader(dbPath);\n            var resp = reader.City(ip);\n            var timezone = resp.Location?.TimeZone;\n            var country = resp.Country?.IsoCode;\n            string? locale = country != null && CountryLocaleMap.TryGetValue(country, out var l) ? l : null;\n            CloakLog.Debug(\"GeoIP: {0} -> tz={1}, country={2}, locale={3}\", ip, timezone, country, locale);\n            return (timezone, locale, ip);\n        }\n        catch (Exception exc)\n        {\n            throw new InvalidOperationException($\"GeoIP lookup failed for {ip}: {exc.Message}\", exc);\n        }\n    }\n\n    // -----------------------------------------------------------------------\n    // Proxy IP resolution\n    // -----------------------------------------------------------------------\n\n    private static string? ResolveProxyIp(string proxyUrl)\n    {\n        try\n        {\n            if (!Uri.TryCreate(proxyUrl, UriKind.Absolute, out var uri))\n                return null;\n            var hostname = uri.Host;\n            if (string.IsNullOrEmpty(hostname))\n                return null;\n\n            // Already a literal IP?","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/dotnet/src/CloakBrowser/GeoIp.cs#L120-L156","documentation":"A MaxMind DatabaseReader was opened and the City lookup threw for the discovered IP; the library wraps that inner exception with the offending IP and message. Typical inner causes are address-not-found-in-database, a corrupted or truncated .mmdb file, or an invalid IP object. The original exception is preserved as InnerException.","triggerScenarios":"Calling ResolveProxyGeoAsync / MaybeResolveGeoIpAsync / Collect with an egress IP that reader.City(ip) rejects — e.g. the IP is private/reserved (VPN/proxy on a LAN), the .mmdb file is corrupted, or the database lacks records for that address range.","commonSituations":"Proxies that surface private CGNAT ranges (100.64.x.x, 10.x.x.x) as the egress IP; partially downloaded or corrupted GeoLite2 database files; IPv6 addresses missing from an old database; concurrent readers hitting a database file being replaced.","solutions":["Inspect exc.InnerException to identify the exact MaxMind failure.","If the egress IP is private/reserved, fix proxy configuration or skip GeoIP — public databases have no city data for it.","Re-download or replace the GeoIP .mmdb database (corruption is the next most likely cause).","Update the MaxMind database to a current build covering recent IPv6 allocations."],"exampleFix":"// before\nvar (tz, locale, ip) = await browser.GeoIp.ResolveProxyGeoAsync(proxyUrl);\n\n// after\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"GeoIP lookup failed\"))\n{\n    _log.Warn(ex.InnerException, \"GeoIP db lookup failed for {Ip}; falling back to default tz\", ip);\n    tz = \"UTC\"; // graceful fallback\n}","handlingStrategy":"try-catch","validationCode":"if (IPAddress.IsPrivate(ip) || ip.IsIPv6LinkLocal)\n    return GeoResult.Unknown; // MaxMind has no city data for private ranges","typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"GeoIP lookup failed\") && ex.InnerException != null)\n{\n    _log.Warn(ex.InnerException, \"GeoIP db error for {Ip}; using default timezone\", ip);\n    tz = \"UTC\";\n}","preventionTips":["Filter private/CGNAT egress IPs before attempting a city lookup.","Use a current, complete GeoLite2/GeoIP2 database and verify its checksum after download.","Avoid replacing the .mmdb file while lookups are in flight."],"tags":["geoip","maxmind","exception-wrapper","database"],"backgroundTag":"geoip-lookup-failed","analyzedSha":"d6bad5de261bedf025280ace1d14e800aee13923","analyzedAt":"2026-08-28T14:13:12.918Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}