{"record":{"id":"4d621f7f71ec5825","repo":"coredns/coredns","slug":"unexpected-failure-looking-up-database-q-schema","errorCode":null,"errorMessage":"unexpected failure looking up database %q schema %q: %v","messagePattern":"unexpected failure looking up database %q schema %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/geoip/geoip.go","lineNumber":61,"sourceCode":"\treader, err := geoip2.Open(dbPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open database file: %v\", err)\n\t}\n\tdb := db{Reader: reader}\n\tschemas := []struct {\n\t\tprovides int\n\t\tname     string\n\t\tvalidate func() error\n\t}{\n\t\t{name: \"city\", provides: city, validate: func() error { _, err := reader.City(probingIP); return err }},\n\t\t{name: \"asn\", provides: asn, validate: func() error { _, err := reader.ASN(probingIP); return err }},\n\t}\n\t// Query the database to figure out the database type.\n\tfor _, schema := range schemas {\n\t\tif err := schema.validate(); err != nil {\n\t\t\t// If we get an InvalidMethodError then we know this database does not provide that schema.\n\t\t\tif _, ok := err.(geoip2.InvalidMethodError); !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"unexpected failure looking up database %q schema %q: %v\", filepath.Base(dbPath), schema.name, err)\n\t\t\t}\n\t\t} else {\n\t\t\tdb.provides |= schema.provides\n\t\t}\n\t}\n\n\tif db.provides == 0 {\n\t\treturn nil, fmt.Errorf(\"database does not provide any supported schema (city, asn)\")\n\t}\n\n\treturn &GeoIP{db: db, edns0: edns0}, nil\n}\n\n// ServeDNS implements the plugin.Handler interface.\nfunc (g GeoIP) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {\n\treturn plugin.NextOrFailure(pluginName, g.Next, ctx, w, r)\n}\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/coredns/coredns/blob/558c9757a92b361e550bdba82d0b4ddf3d12d595/plugin/geoip/geoip.go#L43-L79","documentation":"During newGeoIP the plugin probes each candidate schema (City, ASN) by querying the database. If the probe returns an error that is not geoip2.InvalidMethodError (the sentinel for 'schema not provided'), something unexpected failed while reading the database and startup aborts with this wrapped error including the db filename and schema name.","triggerScenarios":"A corrupt or truncated mmdb file, a database whose search-tree/data sections are damaged, or an incompatible/corrupt mmdb version causing lookup errors other than InvalidMethodError during validation.","commonSituations":"Partially downloaded or interrupted database updates; an encrypted or renamed non-mmdb file that still opens; disk corruption.","solutions":["Re-download the MaxMind database from a trusted source and replace the file.","Verify file integrity (checksum) after download.","Confirm the file is not truncated (compare file size with the published size).","Test the db with a minimal geoip2 reader program to confirm it can be queried."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"r, err := geoip2.Open(dbPath)\nif err == nil {\n    if _, err := r.Country(netip.MustParseAddr(\"8.8.8.8\")); err != nil && !errors.Is(err, geoip2.InvalidMethodError{}) {\n        return fmt.Errorf(\"db probe failed: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, ok := err.(geoip2.InvalidMethodError); !ok {\n    return fmt.Errorf(\"corrupt db %s: %w\", dbPath, err)\n} // otherwise treat as schema-not-provided and continue","preventionTips":["Verify checksums after downloading mmdb files","Avoid interrupted/partial database updates","Probe the db in CI before deploy"],"tags":["coredns","geoip","database"],"backgroundTag":"database-query-failed","analyzedSha":"558c9757a92b361e550bdba82d0b4ddf3d12d595","analyzedAt":"2026-09-06T22:47:02.106Z","contentChangedAt":"2026-09-06T22:47:02.106Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}