kataras/iris · error

unexpected "fsOrDir" argument type of %T (string or fs.FS or

Error message

unexpected "fsOrDir" argument type of %T (string or fs.FS or embed.FS or http.FileSystem)

What it means

This panic comes from iris's helper that converts a user-supplied asset source (a directory path string, fs.FS, embed.FS, or http.FileSystem) into an internal file system. It means the value passed was not one of the four accepted types, so the library cannot serve files from it.

Source

Thrown at context/fs.go:36

//
// This package-level variable can be modified on initialization.
var ResolveFS = func(fsOrDir any) fs.FS {
	if fsOrDir == nil {
		return noOpFS{}
	}

	switch v := fsOrDir.(type) {
	case string:
		if v == "" {
			return noOpFS{}
		}
		return os.DirFS(v)
	case fs.FS:
		return v
	case http.FileSystem: // handles go-bindata.
		return &httpFS{v}
	default:
		panic(fmt.Errorf(`unexpected "fsOrDir" argument type of %T (string or fs.FS or embed.FS or http.FileSystem)`, v))
	}
}

type noOpFS struct{}

func (fileSystem noOpFS) Open(name string) (fs.File, error) { return nil, nil }

// IsNoOpFS reports whether the given "fileSystem" is a no operation fs.
func IsNoOpFS(fileSystem fs.FS) bool {
	_, ok := fileSystem.(noOpFS)
	return ok
}

type httpFS struct {
	fs http.FileSystem
}

func (f *httpFS) Open(name string) (fs.File, error) {

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Convert the argument to one of the accepted types: pass the directory path as a string, an fs.FS (e.g. os.DirFS(dir)), an embed.FS, or an http.FileSystem (e.g. http.FS(embedded) or httpfs from go-bindata).
  2. If using embed, ensure you pass the embedded FS value itself (e.g. //go:embed assets; var assets embed.FS; then pass assets), not a wrapper struct.
  3. Check the function signature you are calling to confirm which of the four types it expects.

Example fix

// before
app.HandleDir("/static", myBytes) // []byte -> panic
// after
app.HandleDir("/static", http.FS(myEmbedFS)) // or a path string / embed.FS
Defensive patterns

Strategy: validation

Validate before calling

switch v.(type) {
case string, fs.FS, embed.FS, http.FileSystem:
    // ok
default:
    panic(fmt.Sprintf("fsOrDir: unsupported type %T", v))
}

Type guard

func isFsOrDir(v interface{}) bool {
    switch v.(type) {
    case string, fs.FS, embed.FS, http.FileSystem:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Calling an API such as HandleDir or EmbeddedDir-like helpers (context/FS-like conversion at context/fs.go) with a value whose type is not string, fs.FS, embed.FS, or http.FileSystem — e.g. passing a []byte, a custom type that merely embeds a string, or a pointer to a struct.

Common situations: Passing a byte slice of embedded assets instead of embed.FS; wrapping an embed.FS in a custom struct; using an older API signature after upgrading iris; passing a *os.File or directory object instead of its path string.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/32addceb388bbd84. Report an issue: GitHub.