{"record":{"id":"56c88aee5a98790d","repo":"ipfs/kubo","slug":"dagstore-key-was-not-a-cid-w","errorCode":null,"errorMessage":"dagStore: key was not a cid: %w","messagePattern":"dagStore: key was not a cid: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dag/export.go","lineNumber":286,"sourceCode":"\n\treturn block.RawData(), nil\n}\n\nfunc (ds *dagStore) Has(ctx context.Context, key string) (bool, error) {\n\t_, err := ds.Get(ctx, key)\n\tif err != nil {\n\t\tif errors.Is(err, ipld.ErrNotFound{}) {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, err\n\t}\n\treturn true, nil\n}\n\nfunc cidFromBinString(key string) (cid.Cid, error) {\n\tl, k, err := cid.CidFromBytes([]byte(key))\n\tif err != nil {\n\t\treturn cid.Undef, fmt.Errorf(\"dagStore: key was not a cid: %w\", err)\n\t}\n\tif l != len(key) {\n\t\treturn cid.Undef, fmt.Errorf(\"dagStore: key was not a cid: had %d bytes leftover\", len(key)-l)\n\t}\n\treturn k, nil\n}\n","sourceCodeStart":268,"sourceCodeEnd":293,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dag/export.go#L268-L293","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Identify the offending key from the wrapped error message and inspect it in the datastore.","Run `ipfs repo gc` and verify blockstore integrity; back up and repair the datastore if keys are corrupt.","Stop any custom code writing non-CID keys directly into the blockstore.","If caused by a version migration issue, upgrade/downgrade kubo consistently and re-verify with `ipfs repo verify` if available."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := cid.Decode(keyString); err != nil {\n    return fmt.Errorf(\"dagStore key %q is not a valid cid: %w\", keyString, err)\n}","typeGuard":null,"tryCatchPattern":"var cidErr *cid.ParseError\nif errors.Is(err, cid.ErrCidTooShort()) || strings.Contains(err.Error(), \"key was not a cid\") {\n    // inspect/repair the offending datastore key\n}","preventionTips":["Never write custom non-CID keys directly into the blockstore.","Run repo gc and integrity checks after crashes or disk errors.","Keep datastore tooling and kubo versions consistent."],"tags":["cid","blockstore","key-parsing","dagstore"],"backgroundTag":"invalid-cid-key","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"}