{"record":{"id":"418eed239d519597","repo":"ipfs/kubo","slug":"dagstore-key-was-not-a-cid-had-d-bytes-leftover","errorCode":null,"errorMessage":"dagStore: key was not a cid: had %d bytes leftover","messagePattern":"dagStore: key was not a cid: had (.+?) bytes leftover","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dag/export.go","lineNumber":289,"sourceCode":"\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":271,"sourceCodeEnd":293,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dag/export.go#L271-L293","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"c, rest, err := cid.CidFromBytes([]byte(key))\nif err != nil || len(rest) != 0 {\n    return fmt.Errorf(\"key must be exactly one CID, got trailing bytes: %q\", key)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"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"}