{"record":{"id":"47c53aa7026070f9","repo":"kataras/iris","slug":"unexpected-fsordir-argument-type-of-t-string-o-47c53a","errorCode":null,"errorMessage":"unexpected \"fsOrDir\" argument type of %T (string or http.FileSystem or embed.FS or fs.FS)","messagePattern":"unexpected \"fsOrDir\" argument type of %T \\(string or http\\.FileSystem or embed\\.FS or fs\\.FS\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context/fs.go","lineNumber":129,"sourceCode":"\tcase embed.FS:\n\t\tdireEtries, err := v.ReadDir(\".\")\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tif len(direEtries) == 0 {\n\t\t\tpanic(\"HandleDir: no directories found under the embedded file system\")\n\t\t}\n\n\t\tsubfs, err := fs.Sub(v, direEtries[0].Name())\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tfileSystem = http.FS(subfs)\n\tcase fs.FS:\n\t\tfileSystem = http.FS(v)\n\tdefault:\n\t\tpanic(fmt.Sprintf(`unexpected \"fsOrDir\" argument type of %T (string or http.FileSystem or embed.FS or fs.FS)`, v))\n\t}\n\n\treturn fileSystem\n}\n\n// FindNames accepts a \"http.FileSystem\" and a root name and returns\n// the list containing its file names.\nfunc FindNames(fileSystem http.FileSystem, name string) ([]string, error) {\n\tif strings.Contains(name, \"..\") {\n\t\treturn nil, fmt.Errorf(\"invalid root name\")\n\t}\n\n\tf, err := fileSystem.Open(name) // it's the root dir.\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer f.Close()\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/fs.go#L111-L147","documentation":"Iris's file-system resolver accepts a string path, http.FileSystem, embed.FS, or fs.FS as the HandleDir argument. When the value passed is none of these supported types, it panics with a message showing the offending Go type via %T.","triggerScenarios":"Passing any value other than string/http.FileSystem/embed.FS/fs.FS as the fsOrDir argument to HandleDir — e.g. a *bytes.Reader, a custom FS interface, or a typed nil of an unsupported type.","commonSituations":"Wrapping assets in a custom filesystem type not implementing fs.FS, passing a byte slice of files, or upgrading Iris where the supported argument set changed and old call sites use obsolete types.","solutions":["Convert the argument to a supported type: a directory path string, http.FileSystem (e.g. http.FS(v)), embed.FS, or fs.FS.","If using a custom filesystem, implement fs.FS so it is accepted via http.FS conversion.","Read the %T in the panic message to find exactly what type leaked in and fix the call site."],"exampleFix":"// before\napp.HandleDir(\"/static\", myBytes) // []byte unsupported\n// after\napp.HandleDir(\"/static\", http.FS(assetsFS)) // embed.FS converted to http.FileSystem","handlingStrategy":"type-guard","validationCode":"switch v := arg.(type) {\ncase string, http.FileSystem, embed.FS, fs.FS:\n  app.HandleDir(\"/static\", v)\ndefault:\n  log.Fatalf(\"unsupported fsOrDir type %T\", arg)\n}","typeGuard":"func isSupportedFS(v any) bool {\n  switch v.(type) {\n  case string, http.FileSystem, embed.FS, fs.FS:\n    return true\n  default:\n    return false\n  }\n}","tryCatchPattern":null,"preventionTips":["Pass only string paths, http.FileSystem, embed.FS, or fs.FS to HandleDir","Wrap custom filesystems with http.FS or implement fs.FS","Check the Iris version's documented HandleDir signature when upgrading"],"tags":["go","panic","type-mismatch","static-files"],"backgroundTag":"invalid-argument-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}