{"record":{"id":"98ef3ba9d2e949d5","repo":"ipfs/kubo","slug":"invalid-cid-q-w","errorCode":null,"errorMessage":"invalid CID %q: %w","messagePattern":"invalid CID %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1746,"sourceCode":"\tExtra:    CreateCmdExtras(SetDoesNotUseRepo(true)),\n\tRun: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {\n\t\tconfirm, _ := req.Options[chrootConfirmOptionName].(bool)\n\t\tif !confirm {\n\t\t\treturn errors.New(\"this is a potentially destructive operation; pass --confirm to proceed\")\n\t\t}\n\n\t\tenc, err := cmdenv.GetCidEncoder(req)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Determine new root CID\n\t\tvar newRootCid cid.Cid\n\t\tif len(req.Arguments) > 0 {\n\t\t\tvar err error\n\t\t\tnewRootCid, err = cmdutils.CidFromArg(req.Arguments[0])\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid CID %q: %w\", req.Arguments[0], err)\n\t\t\t}\n\t\t} else {\n\t\t\t// Default to empty directory\n\t\t\tnewRootCid = ft.EmptyDirNode().Cid()\n\t\t}\n\n\t\t// Get config root to open repo directly\n\t\tcctx := env.(*oldcmds.Context)\n\t\tcfgRoot := cctx.ConfigRoot\n\n\t\t// Open repo directly (daemon must not be running)\n\t\trepo, err := fsrepo.Open(cfgRoot)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"opening repo (is the daemon running?): %w\", err)\n\t\t}\n\t\tdefer repo.Close()\n\n\t\tlocalDS := repo.Datastore()","sourceCodeStart":1728,"sourceCodeEnd":1764,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1728-L1764","documentation":"`ipfs files chroot` parses its optional CID argument with cmdutils.CidFromArg; when parsing fails the underlying error is wrapped as `invalid CID %q: %w`. This means the string supplied as the new root is not a syntactically valid CID (bad multibase/encoding) or an unsupported codec/version.","triggerScenarios":"Passing a bare base58 string, a content hash, an IPFS path (`/ipfs/<cid>`), or a typo'd/truncated CID as the argument to `ipfs files chroot`; passing a CID of a codec that CidFromArg rejects.","commonSituations":"Copy-paste truncation of long CIDv1 strings; confusing a UnixFS path with a CID; using old base58 CIDv0 output where the tooling expects a full CIDv1 string, or vice versa.","solutions":["Pass a valid, complete CID string (verify first with `ipfs cid <string>` or `ipfs cid format`).","Strip any `/ipfs/` prefix and pass only the CID itself.","Omit the argument entirely to reset the MFS root to the empty directory."],"exampleFix":"// before\nipfs files chroot --confirm /ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco\n// after\nipfs files chroot --confirm QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco","handlingStrategy":"validation","validationCode":"ipfs cid format \"$ARG\" > /dev/null || { echo \"not a valid CID: $ARG\"; exit 2; }","typeGuard":"func looksLikeCid(s string) bool { _, err := cid.Decode(s); return err == nil }","tryCatchPattern":"newRoot, err := cmdutils.CidFromArg(arg)\nif err != nil {\n    return fmt.Errorf(\"--%s must be a bare CID (no /ipfs/ prefix), got %q\", flag, arg)\n}","preventionTips":["Validate with `ipfs cid` before passing CIDs to commands","Strip `/ipfs/` prefixes; pass only the CID itself","Copy full CID strings; watch for terminal truncation of long CIDv1s"],"tags":["validation","cid","cli","parsing"],"backgroundTag":"invalid-cid","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"}