{"record":{"id":"24ad112f8288a3db","repo":"AdguardTeam/AdGuardHome","slug":"decoding-db-w","errorCode":null,"errorMessage":"decoding db: %w","messagePattern":"decoding db: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dhcpd/db.go","lineNumber":106,"sourceCode":"\t\tIsStatic: dl.IsStatic,\n\t}, nil\n}\n\n// dbLoad loads stored leases.\nfunc (s *server) dbLoad() (err error) {\n\tdata, err := os.ReadFile(s.conf.dbFilePath)\n\tif err != nil {\n\t\tif !errors.Is(err, os.ErrNotExist) {\n\t\t\treturn fmt.Errorf(\"reading db: %w\", err)\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tdl := &dataLeases{}\n\terr = json.Unmarshal(data, dl)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"decoding db: %w\", err)\n\t}\n\n\tleases := dl.Leases\n\tleases4 := []*dhcpsvc.Lease{}\n\tleases6 := []*dhcpsvc.Lease{}\n\n\tfor _, l := range leases {\n\t\tvar lease *dhcpsvc.Lease\n\t\tlease, err = l.toLease()\n\t\tif err != nil {\n\t\t\tlog.Info(\"dhcp: invalid lease: %s\", err)\n\n\t\t\tcontinue\n\t\t}\n\n\t\tif lease.IP.Is4() {\n\t\t\tleases4 = append(leases4, lease)\n\t\t} else {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/dhcpd/db.go#L88-L124","documentation":"The lease database file was read but its content is not valid JSON matching the dataLeases structure; json.Unmarshal failed. The DB is expected to be a JSON object with a leases array.","triggerScenarios":"Loading a leases file containing truncated JSON, YAML, plain text, or JSON with leases entries of the wrong shape (e.g. leases as object instead of array).","commonSituations":"Hand-editing the file and breaking syntax, interrupted writes (crash during save), or a file from an incompatible version/fork.","solutions":["Validate the file with a JSON linter (jq . leases.json)","Fix or delete the malformed file; dynamic leases will be re-acquired","Restore from backup; ensure the service is stopped when editing to avoid truncated writes"],"exampleFix":"// before\n{ \"leases\": { \"a\": 1 } }\n// after\n{ \"leases\": [] }","handlingStrategy":"validation","validationCode":"if !json.Valid(data) { /* quarantine file and continue with empty DB */ }","typeGuard":"func isValidLeasesJSON(b []byte) bool { return json.Valid(b) }","tryCatchPattern":"if err := s.dbLoad(); err != nil && strings.Contains(err.Error(), \"decoding db\") { /* rename bad file, retry */ }","preventionTips":["Use jq to validate after manual edits","Avoid killing the process during lease saves"],"tags":["dhcp","leases","json","persistence"],"backgroundTag":"corrupted-lease-database","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}