{"record":{"id":"36eb231c774408cf","repo":"ipfs/kubo","slug":"checking-if-new-root-exists-w","errorCode":null,"errorMessage":"checking if new root exists: %w","messagePattern":"checking if new root exists: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1770,"sourceCode":"\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()\n\t\tbs := bstore.NewBlockstore(localDS)\n\n\t\t// Check new root exists locally and is a directory\n\t\thasBlock, err := bs.Has(req.Context, newRootCid)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"checking if new root exists: %w\", err)\n\t\t}\n\t\tif !hasBlock {\n\t\t\t// Special case: empty dir is always available (hardcoded in boxo)\n\t\t\temptyDirCid := ft.EmptyDirNode().Cid()\n\t\t\tif !newRootCid.Equals(emptyDirCid) {\n\t\t\t\treturn fmt.Errorf(\"new root %s does not exist locally; fetch it first with 'ipfs block get'\", enc.Encode(newRootCid))\n\t\t\t}\n\t\t}\n\n\t\t// Validate it's a directory (not a file)\n\t\tif hasBlock {\n\t\t\tblk, err := bs.Get(req.Context, newRootCid)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"reading new root block: %w\", err)\n\t\t\t}\n\t\t\tpbNode, err := dag.DecodeProtobuf(blk.RawData())\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"new root is not a valid dag-pb node: %w\", err)","sourceCodeStart":1752,"sourceCodeEnd":1788,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1752-L1788","documentation":"After opening the local repo, `ipfs files chroot` checks that the proposed new root block exists in the local blockstore (bs.Has). The generic blockstore error is wrapped with this message; separately, if the block is absent and the CID is not the well-known empty-directory CID, the command returns 'new root %s does not exist locally; fetch it first with ipfs block get'.","triggerScenarios":"Chrooting to a CID whose block was never fetched locally (no `ipfs block get`/garbage-collected away); a datastore error (I/O failure, corruption) surfacing from bs.Has(req.Context, newRootCid).","commonSituations":"Referencing a CID seen on the network but never pinned or fetched; a GC run that removed the block; datastore backend failures (disk full, bad flatfs/badger state).","solutions":["Fetch the block first: `ipfs block get <cid>` (with the daemon running) so it lands in the local blockstore, then re-run chroot.","Verify the CID exists on the network at all; a wrong CID will never be fetchable.","If it is a datastore error, check disk space/integrity and inspect daemon logs for datastore errors."],"exampleFix":"# before\nipfs files chroot --confirm bafybei...   # does not exist locally\n# after\nipfs block get bafybei... > /dev/null\nipfs files chroot --confirm bafybei...","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["blockstore","cid","local-data","cli"],"backgroundTag":"root-block-missing-locally","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"}