{"record":{"id":"10b3b763221aeed5","repo":"ipfs/kubo","slug":"s-cannot-add-unnamed-files-to-mfs","errorCode":null,"errorMessage":"%s: cannot add unnamed files to MFS","messagePattern":"(.+?): cannot add unnamed files to MFS","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/add.go","lineNumber":577,"sourceCode":"\t\t\t\tpathAdded, err := api.Unixfs().Add(req.Context, addit.Node(), opts...)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- err\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// Store the root CID for potential fast-provide operation\n\t\t\t\tlastRootCid = pathAdded\n\n\t\t\t\t// creating MFS pointers when optional --to-files is set\n\t\t\t\tif toFilesSet {\n\t\t\t\t\t// The link creates new MFS directory nodes that are not\n\t\t\t\t\t// pinned, so guard it against a concurrent GC. For an\n\t\t\t\t\t// unpinned add the lock is already held above.\n\t\t\t\t\tif dopin {\n\t\t\t\t\t\tdefer ipfsNode.Blockstore.PinLock(req.Context).Unlock(req.Context)\n\t\t\t\t\t}\n\t\t\t\t\tif addit.Name() == \"\" {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: cannot add unnamed files to MFS\", toFilesOptionName)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tif toFilesStr == \"\" {\n\t\t\t\t\t\ttoFilesStr = \"/\"\n\t\t\t\t\t}\n\t\t\t\t\ttoFilesDst, err := checkPath(toFilesStr)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: %w\", toFilesOptionName, err)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tdstAsDir := toFilesDst[len(toFilesDst)-1] == '/'\n\n\t\t\t\t\tif dstAsDir {\n\t\t\t\t\t\tmfsNode, err := mfs.Lookup(ipfsNode.FilesRoot, toFilesDst)\n\t\t\t\t\t\t// confirm dst exists\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination directory %q does not exist: %w\", toFilesOptionName, toFilesDst, err)","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/add.go#L559-L595","documentation":"With `--to-files`, kubo links each added entry into MFS using the entry's name. Stdin adds (`ipfs add -`) have no name, so there is nothing to link the node under; the add goroutine reports this error through errCh.","triggerScenarios":"`ipfs add --to-files=/data -` (reading from stdin); any files.File entry whose Name() is empty combined with ToFiles set.","commonSituations":"Piping downloads or generated bytes into `ipfs add --to-files=...`; CI scripts streaming tarballs via stdin into MFS.","solutions":["Add a real file path so the entry has a name, instead of stdin","Write stdin to a temp file first, then `ipfs add --to-files=/data tmpfile`","Use a plain add for stdin, then `ipfs files cp /ipfs/<cid> /data/name`"],"exampleFix":"// before\ncat stream.bin | ipfs add --to-files=/data -\n// after\nipfs add --to-files=/data /tmp/stream.bin","handlingStrategy":"validation","validationCode":"if toFilesSet && (inputIsStdin || entryName == \"\") {\n  return errors.New(\"--to-files requires named inputs; stdin is not supported\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never combine stdin input with --to-files","Spool stdin to a temp file to give it a name before adding"],"tags":["cli","mfs","stdin","to-files"],"backgroundTag":"unnamed-input-to-mfs","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"}