{"record":{"id":"f8add8f99c853f4a","repo":"ipfs/kubo","slug":"key-not-found-s","errorCode":null,"errorMessage":"key not found: %s","messagePattern":"key not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/commands/diag.go","lineNumber":195,"sourceCode":"\tOptions: []cmds.Option{\n\t\tcmds.BoolOption(diagDatastoreHexOptionName, \"Output hex dump instead of raw bytes\"),\n\t},\n\tNoRemote: true,\n\tPreRun:   DaemonNotRunning,\n\tRun: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {\n\t\tds, closer, err := openDiagDatastore(env)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer closer()\n\n\t\tkeyStr := req.Arguments[0]\n\t\tkey := datastore.NewKey(keyStr)\n\n\t\tval, err := ds.Get(req.Context, key)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, datastore.ErrNotFound) {\n\t\t\t\treturn fmt.Errorf(\"key not found: %s\", keyStr)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"failed to read key: %w\", err)\n\t\t}\n\n\t\tresult := &diagDatastoreGetResult{\n\t\t\tKey:   keyStr,\n\t\t\tValue: val,\n\t\t}\n\n\t\tif hexDump, _ := req.Options[diagDatastoreHexOptionName].(bool); hexDump {\n\t\t\tresult.HexDump = hex.Dump(val)\n\t\t}\n\n\t\treturn cmds.EmitOnce(res, result)\n\t},\n\tType: diagDatastoreGetResult{},\n\tEncoders: cmds.EncoderMap{\n\t\tcmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, result *diagDatastoreGetResult) error {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/diag.go#L177-L213","documentation":"`ipfs diag datastore get <key>` wraps datastore.ErrNotFound as 'key not found: <key>'. The requested key simply does not exist in the datastore; this is a user-input/lookup mismatch, distinguished from other read errors by errors.Is(err, datastore.ErrNotFound).","triggerScenarios":"`ipfs diag datastore get <keyStr>` where ds.Get returns datastore.ErrNotFound for the given key.","commonSituations":"Guessing internal datastore key names; typos in key paths; keys from a different datastore/mount (keystore vs main datastore); keys garbage-collected away.","solutions":["Verify the exact key with `ipfs diag datastore ls` or by listing the datastore directly","Check which datastore mount owns the key (main blockstore vs provider keystore mounts)","Use `ipfs dag get`/`ipfs block get` for content, since block CIDs are stored under prefixed keys"],"exampleFix":"// before\nipfs diag datastore get /blocks/wrongkey\n// error: key not found: /blocks/wrongkey\n// after\nipfs diag datastore ls | grep <key-substring>\nipfs diag datastore get /blocks/CIQ...correctmultihash","handlingStrategy":"validation","validationCode":"val, err := ds.Get(ctx, key)\nif errors.Is(err, datastore.ErrNotFound) { return fmt.Errorf(\"key not found: %s\", keyStr) }","typeGuard":null,"tryCatchPattern":"err := diagDatastoreGet(key)\nif err != nil && strings.Contains(err.Error(), \"key not found\") { listKeysAndRetry() }","preventionTips":["List keys (`ipfs diag datastore ls`) before fetching exact key strings","Remember blockstore keys are prefixed (e.g. /blocks/<base32>), not raw CIDs"],"tags":["datastore","cli","key-not-found"],"backgroundTag":"key-not-found","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}