{"record":{"id":"2678caa8c14fede3","repo":"kataras/iris","slug":"fileserver-fs-is-nil-the-fs-parameter-should-poi","errorCode":null,"errorMessage":"FileServer: fs is nil. The fs parameter should point to a file system of physical system directory or to an embedded one","messagePattern":"FileServer: fs is nil\\. The fs parameter should point to a file system of physical system directory or to an embedded one","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/router/fs.go","lineNumber":167,"sourceCode":"\tAttachments: Attachments{\n\t\tEnable: false,\n\t\tLimit:  0,\n\t\tBurst:  0,\n\t},\n\tAssetValidator: nil,\n\tSPA:            false,\n}\n\n// FileServer returns a Handler which serves files from a specific file system.\n// The first parameter is the file system,\n// if it's a `http.Dir` the files should be located near the executable program.\n// The second parameter is the settings that the caller can use to customize the behavior.\n//\n// See `Party#HandleDir` too.\n// Examples can be found at: https://github.com/kataras/iris/tree/main/_examples/file-server\nfunc FileServer(fs http.FileSystem, options DirOptions) context.Handler {\n\tif fs == nil {\n\t\tpanic(\"FileServer: fs is nil. The fs parameter should point to a file system of physical system directory or to an embedded one\")\n\t}\n\n\t// Make sure index name starts with a slash.\n\tif options.IndexName != \"\" {\n\t\toptions.IndexName = prefix(options.IndexName, \"/\")\n\t}\n\n\t// Make sure PushTarget's paths are in the proper form.\n\tfor path, filenames := range options.PushTargets {\n\t\tfor idx, filename := range filenames {\n\t\t\tfilenames[idx] = filepath.ToSlash(filename)\n\t\t}\n\t\toptions.PushTargets[path] = filenames\n\t}\n\n\tif !options.Attachments.Enable {\n\t\t// make sure rate limiting is not used when attachments are not.\n\t\toptions.Attachments.Limit = 0","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/core/router/fs.go#L149-L185","documentation":"FileServer (used by Party.HandleDir) serves files from an http.FileSystem. It panics immediately if the fs parameter is nil because there is no file system to serve from. The parameter must point to a physical system directory or an embedded (go:embed) file system.","triggerScenarios":"Calling router.FileServer(nil, options) or Party.HandleDir with a nil http.FileSystem — e.g. http.Dir(\"\") misuse, an embedded FS variable that failed to bind, or a helper returning (http.FileSystem, error) whose error path was ignored.","commonSituations":"Passing the result of http.Dir with wrong path handling; using go:embed but assigning to the wrong variable so the FS is nil; wrapping http.FS(embedded) conversions incorrectly; conditional FS setup skipped in tests.","solutions":["Pass a valid http.FileSystem, e.g. http.Dir(\"./public\") for a physical directory","For embedded assets use //go:embed and pass http.FS(embeddedFS) (or iris.PrefixEmbed FS helpers)","If the FS comes from a function, check it for nil before calling FileServer"],"exampleFix":"// before\nvar fs http.FileSystem\nrouter.HandleDir(\"/static\", fs) // panics: fs is nil\n// after\nfs := http.Dir(\"./public\") // or http.FS(embeddedFS)\nrouter.HandleDir(\"/static\", fs)","handlingStrategy":"validation","validationCode":"func mustFS(fs http.FileSystem) http.FileSystem {\n    if fs == nil {\n        panic(\"FileServer: provide http.Dir(path) or http.FS(embedded)\")\n    }\n    return fs\n}","typeGuard":"func isNilFS(fs http.FileSystem) bool {\n    return fs == nil\n}","tryCatchPattern":"func handleDirSafe(app *iris.Application, path string, fs http.FileSystem, opts router.DirOptions) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"HandleDir(%q) failed: %v\", path, r)\n        }\n    }()\n    if isNilFS(fs) {\n        fs = http.Dir(\"./public\")\n    }\n    app.HandleDir(path, fs, opts)\n}","preventionTips":["Use http.Dir(\"./public\") or http.FS(embeddedFS) directly at the call site","Verify go:embed variables are populated (non-nil) at init","Check any helper that returns an http.FileSystem for nil before use","Add a startup smoke test that hits one static file to catch nil FS early"],"tags":["panic","nil-argument","file-server","static-files"],"backgroundTag":"nil-argument-panic","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}