{"record":{"id":"f80c61fc118f23d6","repo":"ipfs/kubo","slug":"invalid-cid-version-q","errorCode":null,"errorMessage":"invalid cid version: %q","messagePattern":"invalid cid version: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/cid.go","lineNumber":104,"sourceCode":"\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 {\n\t\t\topts.newBase = mbase.Encoding(-1)\n\t\t}\n\n\t\treturn emitCids(req, resp, opts)\n\t},\n\tPostRun: cmds.PostRunMap{\n\t\tcmds.CLI: streamResult(func(v any, out io.Writer) nonFatalError {\n\t\t\tr := v.(*CidFormatRes)\n\t\t\tif r.ErrorMsg != \"\" {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/cid.go#L86-L122","documentation":"Fired by the `ipfs cid` command when the --cid-ver (or equivalent) option is set to a string other than \"\", \"0\", or \"1\". It is a validation guard over the user-supplied version argument: only CIDv0 and CIDv1 conversions are supported, so any other value (typo like \"v1\", \"2\", \"3\") is rejected before any conversion runs.","triggerScenarios":"Passing --cid-ver=2, --cid-ver=v1, or any typo'd version value to `ipfs cid format`.","commonSituations":"Assuming CIDv2 or 'v1' prefixed values are accepted; scripts parameterizing the version with an unvalidated value; future-version guesswork.","solutions":["Use exactly 0 or 1 (or omit the flag to keep the input version)","Validate the version value in scripts before passing it","Use CIDv1 (there is no CIDv2); for new hash functions stick with version 1"],"exampleFix":"// before\nipfs cid format --cid-ver=v1 <cid>\n// after\nipfs cid format --cid-ver=1 <cid>","handlingStrategy":"validation","validationCode":"validVersions := map[string]struct{}{\"\": {}, \"0\": {}, \"1\": {}}\nif _, ok := validVersions[ver]; !ok {\n    return fmt.Errorf(\"invalid cid version: %q\", ver)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"invalid cid version\") {\n    // sanitize --cid-ver input and retry\n}","preventionTips":["Only allow \"\", \"0\", \"1\" for version options","Never prefix version values with 'v'","Sanitize user/script-supplied version input"],"tags":["cli","cid","validation","bad-input"],"backgroundTag":"invalid-enum-value","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"}