ipfs/kubo · error

dagStore: key was not a cid

Error message

dagStore: key was not a cid: %w

What it means

`cidFromBinString` parses a dagStore key string as a CID using `cid.CidFromBytes`. If the bytes are not a valid CID, the parse error is wrapped with this `dagStore` prefix. The dagStore `Get` implementation uses it to translate storage keys back into CIDs, so a key that fails to parse means the key is malformed or was written by an incompatible component.

Solutions

  1. Identify the offending key from the wrapped error message and inspect it in the datastore.
  2. Run `ipfs repo gc` and verify blockstore integrity; back up and repair the datastore if keys are corrupt.
  3. Stop any custom code writing non-CID keys directly into the blockstore.
  4. If caused by a version migration issue, upgrade/downgrade kubo consistently and re-verify with `ipfs repo verify` if available.
Defensive patterns

Strategy: validation

Validate before calling

if _, err := cid.Decode(keyString); err != nil {
    return fmt.Errorf("dagStore key %q is not a valid cid: %w", keyString, err)
}

Try / catch

var cidErr *cid.ParseError
if errors.Is(err, cid.ErrCidTooShort()) || strings.Contains(err.Error(), "key was not a cid") {
    // inspect/repair the offending datastore key
}

Prevention

When it happens

Trigger: Calling dagStore `Get` (indirectly, e.g. via `ipfs dag export --local-only`'s partial CAR exporter which treats the blockstore as a DAG store) with a blockstore key whose bytes are not a valid CID binary string.

Common situations: A corrupted or hand-modified blockstore directory; a datastore shared with an older/newer key encoding; custom tooling that inserted non-CID keys into the blockstore.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/56c88aee5a98790d. Report an issue: GitHub.

Appendix: source

Thrown at core/commands/dag/export.go:286

	return block.RawData(), nil
}

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)