ipfs/kubo · error
dagStore: key was not a cid: had %d bytes leftover
Error message
dagStore: key was not a cid: had %d bytes leftover
What it means
The sibling validation in `cidFromBinString`: even when `cid.CidFromBytes` succeeds, it may consume fewer bytes than the key holds (`l != len(key)`). A dagStore key must be exactly one CID with no trailing bytes, so leftover bytes indicate a malformed key and this error reports how many bytes remain.
Source
Thrown at core/commands/dag/export.go:289
func (ds *dagStore) Has(ctx context.Context, key string) (bool, error) {
_, err := ds.Get(ctx, key)
if err != nil {
if errors.Is(err, ipld.ErrNotFound{}) {
return false, nil
}
return false, err
}
return true, nil
}
func cidFromBinString(key string) (cid.Cid, error) {
l, k, err := cid.CidFromBytes([]byte(key))
if err != nil {
return cid.Undef, fmt.Errorf("dagStore: key was not a cid: %w", err)
}
if l != len(key) {
return cid.Undef, fmt.Errorf("dagStore: key was not a cid: had %d bytes leftover", len(key)-l)
}
return k, nil
}
View on GitHub (pinned to 329838acdf)
Solutions
- Check the key format of the underlying blockstore/datastore; it must be the exact CID bytes with no extra bytes.
- Fix or regenerate keys in the custom writer that produced suffixed keys.
- Run `ipfs repo gc` / rebuild the local datastore if corruption shifted key boundaries.
- Capture the full offending key from the error and open an issue if it came from stock kubo.
Defensive patterns
Strategy: validation
Validate before calling
c, rest, err := cid.CidFromBytes([]byte(key))
if err != nil || len(rest) != 0 {
return fmt.Errorf("key must be exactly one CID, got trailing bytes: %q", key)
} Prevention
- Ensure key writers store the CID bytes alone, never CID + suffix.
- Validate key format when migrating between datastore schemas.
- Rebuild the datastore if byte boundaries appear shifted.
When it happens
Trigger: dagStore `Get` receives a key string that starts with valid CID bytes but contains additional trailing data — e.g. a key encoding that embeds the CID as a prefix rather than the whole value.
Common situations: A datastore written by tooling that concatenated CID + suffix keys; data corruption shifting byte boundaries; using a dagStore view over a blockstore with a different key format.
Related errors
- dagStore: key was not a cid: %w
- CheckCIDSize: getting dag: %w
- checking if new root exists: %w
- new root %s does not exist locally; fetch it first with 'ipf
- pin check failed: %w
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/418eed239d519597.
Report an issue: GitHub.