{"record":{"id":"4eaec633608a9d95","repo":"ipfs/kubo","slug":"expected-a-regular-file-4eaec6","errorCode":null,"errorMessage":"expected a regular file","messagePattern":"expected a regular file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dag/put.go","lineNumber":94,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tencoder, err := multicodec.LookupEncoder(uint64(scodec))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar adder ipld.NodeAdder = api.Dag()\n\tif dopin {\n\t\tadder = api.Dag().Pinning()\n\t}\n\tb := ipld.NewBatch(req.Context, adder)\n\n\tit := req.Files.Entries()\n\tfor it.Next() {\n\t\tfile := files.FileFromEntry(it)\n\t\tif file == nil {\n\t\t\treturn fmt.Errorf(\"expected a regular file\")\n\t\t}\n\n\t\tnode := basicnode.Prototype.Any.NewBuilder()\n\t\tif err := decoder(node, file); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tn := node.Build()\n\n\t\tbd := bytes.NewBuffer([]byte{})\n\t\tif err := encoder(n, bd); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tblockCid, err := cidPrefix.Sum(bd.Bytes())\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tblk, err := blocks.NewBlockWithCid(bd.Bytes(), blockCid)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dag/put.go#L76-L112","documentation":"`ipfs dag put` iterates req.Files entries and each must be a real file whose bytes it decodes with the codec chosen by --store-codec/--input-codec. If an entry is not a file (directory, symlink-ish entry, or missing handle), the command fails with \"expected a regular file\".","triggerScenarios":"`ipfs dag put` given a directory path; piping nothing into `ipfs dag put -` so the stdin entry is not a file; RPC multipart with directory entries.","commonSituations":"Forgetting `ipfs add -r`-style recursion expectations — dag put does not walk directories; shell redirect mistakes producing empty stdin; API clients sending malformed multipart.","solutions":["Pass a single regular file: `ipfs dag put file.json` or `cat data | ipfs dag put -`","Check the path is a file not a directory","Ensure the RPC client sends the payload as a file part"],"exampleFix":"// before\nipfs dag put ./data-dir\n// error: expected a regular file\n// after\nipfs dag put ./data-dir/obj.json","handlingStrategy":"validation","validationCode":"// ensure input is a regular file before dag put\nst, err := os.Stat(dataPath)\nif err != nil {\n    return err\n}\nif st.IsDir() {\n    return fmt.Errorf(\"dag put requires a file; %s is a directory\", dataPath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `ipfs add -r` for directories; dag put is per-file","When piping, verify the producer actually wrote data","Send file parts, not directory parts, in RPC multipart bodies"],"tags":["cli","dag-put","input-validation"],"backgroundTag":"expected-regular-file","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"}