ipfs/kubo · error

%s was not a file

Error message

%s was not a file

What it means

Fired by `ipfs files read` after an MFS lookup succeeds but the node at the given path is not an *mfs.File — i.e. it is a directory (or another non-file MFS node). Reading requires a regular UnixFS file, so the command refuses; the user passed a directory path to a read-style operation.

Source

Thrown at core/commands/files.go:851

	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
		nd, err := cmdenv.GetNode(env)
		if err != nil {
			return err
		}

		path, err := checkPath(req.Arguments[0])
		if err != nil {
			return err
		}

		fsn, err := mfs.Lookup(nd.FilesRoot, path)
		if err != nil {
			return fmt.Errorf("%s: %w", path, err)
		}

		fi, ok := fsn.(*mfs.File)
		if !ok {
			return fmt.Errorf("%s was not a file", path)
		}

		rfd, err := fi.Open(req.Context, mfs.Flags{Read: true})
		if err != nil {
			return err
		}

		defer rfd.Close()

		offset, _ := req.Options[offsetOptionName].(int64)
		if offset < 0 {
			return fmt.Errorf("cannot specify negative offset")
		}

		filen, err := rfd.Size()
		if err != nil {
			return err
		}

View on GitHub (pinned to 329838acdf)

Solutions

  1. List the directory with 'ipfs files ls <path>' and read one of its files
  2. Use 'ipfs ls' or gateway-style listing for directory contents instead
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at core/commands/files.go:851 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/371ab65c303198c8. Report an issue: GitHub.