{"record":{"id":"6cdf358fcaa26aac","repo":"ipfs/kubo","slug":"s-mfs-destination-directory-q-does-not-exist","errorCode":null,"errorMessage":"%s: MFS destination directory %q does not exist: %w","messagePattern":"(.+?): MFS destination directory %q does not exist: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/add.go","lineNumber":595,"sourceCode":"\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)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// confirm dst is a dir\n\t\t\t\t\t\tif mfsNode.Type() != mfs.TDir {\n\t\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination %q is not a directory\", toFilesOptionName, toFilesDst)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// if MFS destination is a dir, append filename to the dir path\n\t\t\t\t\t\ttoFilesDst += gopath.Base(addit.Name())\n\t\t\t\t\t}\n\n\t\t\t\t\t// error if we try to overwrite a preexisting file destination\n\t\t\t\t\tif fileAddedToMFS && !dstAsDir {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination is a file: only one entry can be copied to %q\", toFilesOptionName, toFilesDst)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t_, err = mfs.Lookup(ipfsNode.FilesRoot, gopath.Dir(toFilesDst))","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/add.go#L577-L613","documentation":"When the `--to-files` destination ends with '/', it is treated as a directory and kubo looks it up under the MFS root to confirm it exists. If mfs.Lookup fails (path absent), the error is wrapped with the option name and destination for context.","triggerScenarios":"`ipfs add --to-files=/nonexistent/ file` (trailing slash, directory missing in MFS); typo'd MFS directories; destination removed by a prior `ipfs files rm -r` before the add ran.","commonSituations":"Scripts assuming a target directory exists in MFS; fresh nodes with empty /; destinations under paths never created via `ipfs files mkdir -p`.","solutions":["Create the directory first: `ipfs files mkdir -p /data`","Drop the trailing slash so the destination is treated as a file path","Verify the target exists with `ipfs files stat /data/` before adding"],"exampleFix":"// before\nipfs add --to-files=/data/ report.md   # /data does not exist\n// after\nipfs files mkdir -p /data && ipfs add --to-files=/data/ report.md","handlingStrategy":"try-catch","validationCode":"if strings.HasSuffix(dst, \"/\") {\n  if _, err := api.Files().Stat(ctx, dst); err != nil {\n    return fmt.Errorf(\"MFS directory missing: %w\", err)\n  }\n}","typeGuard":null,"tryCatchPattern":"err := ipfsAdd(ctx, args...)\nvar cmdErr *cmds.Error\nif errors.As(err, &cmdErr) && strings.Contains(cmdErr.Message, \"does not exist\") {\n  if err := api.Files().Mkdir(ctx, dirDst, optFiles.MkdirParents(true)); err == nil {\n    err = ipfsAdd(ctx, args...)\n  }\n}","preventionTips":["Run `ipfs files mkdir -p` for destination directories before bulk adds","Stat the MFS destination before invoking add in scripts","Avoid trailing-slash directory destinations unless the dir is known to exist"],"tags":["cli","mfs","to-files","not-found"],"backgroundTag":"mfs-destination-not-found","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"}