{"record":{"id":"5ee419511c7284e9","repo":"ipfs/kubo","slug":"cannot-convert-to-cidv0-with-any-codec-other-than","errorCode":null,"errorMessage":"cannot convert to CIDv0 with any codec other than dag-pb","messagePattern":"cannot convert to CIDv0 with any codec other than dag-pb","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/cid.go","lineNumber":95,"sourceCode":"\t\topts.fmtStr = fmtStr\n\n\t\tif codecStr != \"\" {\n\t\t\tvar codec mc.Code\n\t\t\terr := codec.Set(codecStr)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\topts.newCodec = uint64(codec)\n\t\t} // otherwise, leave it as 0 (not a valid IPLD codec)\n\n\t\tswitch verStr {\n\t\tcase \"\":\n\t\t\tif baseStr != \"\" {\n\t\t\t\topts.verConv = toCidV1\n\t\t\t}\n\t\tcase \"0\":\n\t\t\tif opts.newCodec != 0 && opts.newCodec != cid.DagProtobuf {\n\t\t\t\treturn errors.New(\"cannot convert to CIDv0 with any codec other than dag-pb\")\n\t\t\t}\n\t\t\tif baseStr != \"\" && baseStr != \"base58btc\" {\n\t\t\t\treturn errors.New(\"cannot convert to CIDv0 with any multibase other than the implicit base58btc\")\n\t\t\t}\n\t\t\topts.verConv = toCidV0\n\t\tcase \"1\":\n\t\t\topts.verConv = toCidV1\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"invalid cid version: %q\", verStr)\n\t\t}\n\n\t\tif baseStr != \"\" {\n\t\t\tencoder, err := mbase.EncoderByName(baseStr)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\topts.newBase = encoder.Encoding()\n\t\t} else {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/cid.go#L77-L113","documentation":"`ipfs cid base32`/`cid format` with --cid-ver=0 (or version option '0') refuses conversion to CIDv0 when a different codec was requested. CIDv0 is by definition dag-pb with the implicit raw multihash, so any other codec cannot be represented as v0.","triggerScenarios":"Running `ipfs cid format --cid-codec=raw --cid-ver=0 <cid>` or setting the codec option to any non-empty value other than dag-pb (codec 0x70) while requesting version 0.","commonSituations":"Converting raw/identity or dag-cbor CIDs down to v0 for legacy compatibility; scripts forcing --cid-ver=0 while also passing --cid-codec.","solutions":["Keep dag-pb codec (or omit --cid-codec) when converting to CIDv0","Use --cid-ver=1 if you need a non-dag-pb codec","Drop the codec option entirely and only pass --cid-ver=0"],"exampleFix":"// before\nipfs cid format --cid-codec=raw --cid-ver=0 <cid>\n// after\nipfs cid format --cid-codec=dag-pb --cid-ver=0 <cid>","handlingStrategy":"validation","validationCode":"if ver == 0 && codec != \"\" && codec != \"dag-pb\" {\n    return fmt.Errorf(\"codec %s incompatible with CIDv0\", codec)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"codec other than dag-pb\") {\n        // fall back to CIDv1\n    }\n}","preventionTips":["Only pass --cid-codec when converting to CIDv1","Never combine --cid-ver=0 with a codec override","Check input codec with `ipfs cid format --format=%c` first"],"tags":["cli","cid","codec","validation"],"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"}