ipfs/kubo · error
failed to read key: %w
Error message
failed to read key: %w
What it means
`ipfs diag datastore get <key>` wraps any datastore read error that is NOT ErrNotFound as 'failed to read key'. It signals real I/O or backend problems (corruption, permissions, backend failure) rather than a missing key.
Source
Thrown at core/commands/diag.go:197
},
NoRemote: true,
PreRun: DaemonNotRunning,
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
ds, closer, err := openDiagDatastore(env)
if err != nil {
return err
}
defer closer()
keyStr := req.Arguments[0]
key := datastore.NewKey(keyStr)
val, err := ds.Get(req.Context, key)
if err != nil {
if errors.Is(err, datastore.ErrNotFound) {
return fmt.Errorf("key not found: %s", keyStr)
}
return fmt.Errorf("failed to read key: %w", err)
}
result := &diagDatastoreGetResult{
Key: keyStr,
Value: val,
}
if hexDump, _ := req.Options[diagDatastoreHexOptionName].(bool); hexDump {
result.HexDump = hex.Dump(val)
}
return cmds.EmitOnce(res, result)
},
Type: diagDatastoreGetResult{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, result *diagDatastoreGetResult) error {
if result.HexDump != "" {
fmt.Fprintf(w, "Key: %s\nHex Dump:\n%s", result.Key, result.HexDump)View on GitHub (pinned to 329838acdf)
Solutions
- Check the wrapped underlying error in verbose output and daemon/diag logs
- Verify disk space, permissions, and filesystem health on the repo directory
- Repair or restore the datastore (backend-specific repair tools, or re-init and re-import from backups)
Defensive patterns
Strategy: try-catch
Try / catch
err := diagDatastoreGet(key)
if err != nil && strings.Contains(err.Error(), "failed to read key") { inspectUnderlying(err); checkDiskHealth() } Prevention
- Unwrap and log the underlying datastore error to identify the backend failure
- Monitor disk space and permissions on the repo directory
- Back up the repo and keep backend repair tools available
When it happens
Trigger: ds.Get(req.Context, key) returns an error other than datastore.ErrNotFound: disk I/O failure, permission denied, corrupt backend (badger/levelds/pebble) errors.
Common situations: Disk full or failing; wrong permissions on the repo directory; corrupted datastore backend after a crash; container filesystem issues.
Related errors
- failed to open repo: %w
- key not found: %s
- reading new root block: %w
- encoding PEM block: %w
- flushing %s: %w
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/35e918c10158d83f.
Report an issue: GitHub.