ipfs/kubo · error

cannot delete root

Error message

cannot delete root

What it means

First guard in removePath (called by `ipfs files rm`): it refuses to remove the MFS root '/'. Deleting the root would leave the node's files layer without a valid root, so the path argument is rejected before any lookup. Generic sentinel-style validation of the target path.

Source

Thrown at core/commands/files.go:1433

				errs = append(errs, fmt.Errorf("%s: %w", path, err))
			}
		}
		if len(errs) > 0 {
			for _, err = range errs {
				e := res.Emit(err.Error())
				if e != nil {
					return e
				}
			}
			return fmt.Errorf("can't remove some files")
		}
		return nil
	},
}

func removePath(filesRoot *mfs.Root, path string, force bool, dashr bool) error {
	if path == "/" {
		return fmt.Errorf("cannot delete root")
	}

	// 'rm a/b/c/' will fail unless we trim the slash at the end
	if path[len(path)-1] == '/' {
		path = path[:len(path)-1]
	}

	dir, name := gopath.Split(path)

	pdir, err := getParentDir(filesRoot, dir)
	if err != nil {
		if force && err == os.ErrNotExist {
			return nil
		}
		return err
	}

	if force {

View on GitHub (pinned to 329838acdf)

Solutions

  1. Remove the contents instead of the root: `ipfs files rm -r /<child>` for each child.
  2. To reset MFS entirely, reinitialize or replace the root via the node-level root APIs rather than `files rm /`.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/commands/files.go:1433 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/fcc4d0e9f69b388a. Report an issue: GitHub.