{"record":{"id":"a8898e0ce41f90b5","repo":"ipfs/kubo","slug":"new-root-must-be-a-directory-got-s","errorCode":null,"errorMessage":"new root must be a directory, got %s","messagePattern":"new root must be a directory, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1795,"sourceCode":"\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\n\t\t// Write new root\n\t\terr = localDS.Put(req.Context, node.FilesRootDatastoreKey, newRootCid.Bytes())\n\t\tif err != nil {","sourceCodeStart":1777,"sourceCodeEnd":1813,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1777-L1813","documentation":"Final type check in the root-replacement validation: the block is a valid UnixFS node but its type is neither TDirectory nor THAMTShard (e.g. a raw file or a symlink), so it cannot serve as the MFS root. The actual node type is interpolated into the message; no state has been modified.","triggerScenarios":"Thrown at core/commands/files.go:1795 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide the CID of a UnixFS directory (or HAMT-sharded directory) instead of a file, e.g. the root of `ipfs add -r <folder>`.","If a file was intended, place it under a directory and use that directory's CID as the new root."],"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"}