{"record":{"id":"e305b09cb493b82a","repo":"gofiber/fiber","slug":"static-w","errorCode":null,"errorMessage":"static: %w","messagePattern":"static: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/static/static.go","lineNumber":338,"sourceCode":"\t\t// Reset response to default\n\t\tc.RequestCtx().SetContentType(\"\") // Issue #420\n\t\tc.RequestCtx().Response.SetStatusCode(fiber.StatusOK)\n\t\tc.RequestCtx().Response.SetBodyString(\"\")\n\n\t\t// Next middleware\n\t\treturn c.Next()\n\t}\n}\n\n// isFile checks if the root is a file.\nfunc isFile(root string, filesystem fs.FS) (bool, error) {\n\tvar file fs.File\n\tvar err error\n\n\tif filesystem != nil {\n\t\tfile, err = filesystem.Open(root)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"static: %w\", err)\n\t\t}\n\t\tdefer func() {\n\t\t\t_ = file.Close() //nolint:errcheck // not needed\n\t\t}()\n\t} else {\n\t\tfile, err = os.Open(filepath.Clean(root))\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"static: %w\", err)\n\t\t}\n\t\tdefer func() {\n\t\t\t_ = file.Close() //nolint:errcheck // not needed\n\t\t}()\n\t}\n\n\tstat, err := file.Stat()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"static: %w\", err)\n\t}","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/static/static.go#L320-L356","documentation":"Thrown by isFile when a custom fs.FS was supplied and filesystem.Open(root) returns an error. The %w wraps the fs.FS error. This fires before any stat: the configured root path could not be opened within the provided/embedded filesystem.","triggerScenarios":"Static middleware is configured with an FS (e.g. embed.FS, io/fs overlay) and the root path does not exist in that FS, is not a regular file path the FS recognizes, or permission/scope rules of the FS reject it.","commonSituations":"embed.FS path that omits the package-relative prefix (e.g. \"./static\" vs \"static\"); root pointing outside an fs.Sub-rooted filesystem; typo in the root; embed directive that didn't include the files.","solutions":["Verify the path exists in the FS with fs.Stat(filesystem, root) before configuring the middleware.","For embed.FS, use the path relative to the directory containing the //go:embed directive, and ensure the embed pattern actually includes it.","If using fs.Sub, make sure root is relative to the sub-root.","Spell-check the root and confirm the build includes the embedded files."],"exampleFix":"// before\napp.Use(\"/\", static.New(\"assets\", static.FS(embeddedFS)))\n// -> static: open assets: no such file\n\n// after — verify, and use the correct path inside the FS\nif _, err := fs.Stat(embeddedFS, \"static/assets\"); err != nil { log.Fatal(err) }\napp.Use(\"/\", static.New(\"static/assets\", static.FS(embeddedFS)))","handlingStrategy":"validation","validationCode":"// Verify the path exists inside the FS before wiring up static.\nif _, err := fs.Stat(filesystem, root); err != nil {\n    log.Fatalf(\"static FS root %q: %v\", root, err)\n}\napp.Use(\"/\", static.New(root, static.FS(filesystem)))","typeGuard":"func fsPathExists(fsys fs.FS, p string) bool {\n    if fsys == nil { return false }\n    _, err := fs.Stat(fsys, p)\n    return err == nil\n}","tryCatchPattern":"_, err := isFile(root, filesystem)\nif err != nil {\n    log.Printf(\"static FS open failed for %q, disabling static: %v\", root, err)\n    // proceed without static, or fail fast at startup\n}","preventionTips":["For embed.FS, use paths relative to the //go:embed directory and confirm the embed pattern includes them.","If using fs.Sub, remember root is relative to the sub-root.","Add a startup fs.Stat check for the static root.","Unit-test static config against a known-good embedded fixture."],"tags":["static","filesystem","embed","open"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}