{"record":{"id":"cdcddf0cdcffae59","repo":"ipfs/kubo","slug":"new-root-is-not-a-valid-unixfs-node-w","errorCode":null,"errorMessage":"new root is not a valid UnixFS node: %w","messagePattern":"new root is not a valid UnixFS node: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1792,"sourceCode":"\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)\n\t\t\t}\n\t\t\tfsNode, err := ft.FSNodeFromBytes(pbNode.Data())\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"new root is not a valid UnixFS node: %w\", err)\n\t\t\t}\n\t\t\tif fsNode.Type() != ft.TDirectory && fsNode.Type() != ft.THAMTShard {\n\t\t\t\treturn fmt.Errorf(\"new root must be a directory, got %s\", fsNode.Type())\n\t\t\t}\n\t\t}\n\n\t\t// Get old root for display (if exists)\n\t\tvar oldRootStr string\n\t\toldRootBytes, err := localDS.Get(req.Context, node.FilesRootDatastoreKey)\n\t\tif err == nil {\n\t\t\toldRootCid, err := cid.Cast(oldRootBytes)\n\t\t\tif err == nil {\n\t\t\t\toldRootStr = enc.Encode(oldRootCid)\n\t\t\t}\n\t\t} else if !errors.Is(err, datastore.ErrNotFound) {\n\t\t\treturn fmt.Errorf(\"reading current MFS root: %w\", err)\n\t\t}\n","sourceCodeStart":1774,"sourceCodeEnd":1810,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1774-L1810","documentation":"Next validation step for the new MFS root: the block decoded as dag-pb, but ft.FSNodeFromBytes rejected its embedded data, so the node is dag-pb yet not a UnixFS directory (e.g. a plain dag-pb node without UnixFS metadata). The root replacement stops before writing anything.","triggerScenarios":"Thrown at core/commands/files.go:1792 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a CID produced by UnixFS directory construction (`ipfs add` of a folder or MFS flush), not arbitrary dag-pb data.","Check the block with `ipfs dag get <cid>` to see its actual structure before retrying."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}