{"record":{"id":"d776945980f140f9","repo":"ipfs/kubo","slug":"can-t-convert-non-dag-pb-nodes-to-cidv0","errorCode":null,"errorMessage":"can't convert non-dag-pb nodes to cidv0","messagePattern":"can't convert non-dag-pb nodes to cidv0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/cid.go","lineNumber":256,"sourceCode":"\t\t\tres.ErrorMsg = err.Error()\n\t\t} else {\n\t\t\tres.Formatted = str\n\t\t}\n\t\temitErr = resp.Emit(res)\n\t}\n\tif emitErr != nil {\n\t\treturn emitErr\n\t}\n\terr := itr.err()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc toCidV0(c cid.Cid) (cid.Cid, error) {\n\tif c.Type() != cid.DagProtobuf {\n\t\treturn cid.Cid{}, fmt.Errorf(\"can't convert non-dag-pb nodes to cidv0\")\n\t}\n\treturn cid.NewCidV0(c.Hash()), nil\n}\n\nfunc toCidV1(c cid.Cid) (cid.Cid, error) {\n\treturn cid.NewCidV1(c.Type(), c.Hash()), nil\n}\n\ntype CodeAndName struct {\n\tCode int\n\tName string\n}\n\nconst (\n\tprefixOptionName  = \"prefix\"\n\tnumericOptionName = \"numeric\"\n)\n","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/cid.go#L238-L274","documentation":"toCidV0 performs the actual CID-to-v0 conversion after option validation and re-checks the codec: only dag-pb (0x70) nodes can be CIDv0. This fires when the new codec was not set via options (so the earlier guard was skipped) but the source CID itself carries a non-dag-pb codec.","triggerScenarios":"`ipfs cid format --cid-ver=0 <raw-or-dag-cbor-cid>` where the input CID's own codec is not dag-pb; converting an identity/raw coded CID to v0.","commonSituations":"Assuming a raw block CID can be 'downgraded' to v0; legacy tooling that expects all CIDs to be v0-convertible; converting multihash-only via c.Hash() from non-dag-pb inputs.","solutions":["Convert to CIDv1 instead: ipfs cid format --cid-ver=1 <cid>","Re-add the content as dag-pb (e.g. `ipfs add --cid-version 0`) to get a v0 CID","Use `ipfs dag put` with codec dag-pb before attempting v0 conversion"],"exampleFix":"// before\nipfs cid format --cid-ver=0 bafkrei...  // raw codec\n// after\nipfs cid format --cid-ver=1 bafkrei...","handlingStrategy":"validation","validationCode":"parsed, err := cid.Decode(cidStr)\nif err == nil && parsed.Type() != cid.DagProtobuf {\n    // do not request CIDv0\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"non-dag-pb\") {\n    v1, _ := cid.CidFromHexString(cidStr)\n    v1c := cid.NewCidV1(v1.Type(), v1.Hash())\n    _ = v1c\n}","preventionTips":["Check c.Type() before requesting v0 conversion","Prefer CIDv1 for non-dag-pb content","Remember CIDv0 implies dag-pb by specification"],"tags":["cli","cid","codec","dag-pb"],"backgroundTag":"cidv0-codec-incompatible","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"}