{"record":{"id":"e4ecc8378693aa26","repo":"gofiber/fiber","slug":"stat-q-w","errorCode":null,"errorMessage":"stat %q: %w","messagePattern":"stat %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"res.go","lineNumber":1175,"sourceCode":"\t\tif cacheControlValue != \"\" {\n\t\t\tresponse.Header.Set(HeaderCacheControl, cacheControlValue)\n\t\t}\n\n\t\treturn nil\n\t}\n\n\treturn nil\n}\n\nfunc sendFileContentLength(path string, cfg SendFile) (int64, error) {\n\tif cfg.FS != nil {\n\t\tcleanPath := pathpkg.Clean(utils.TrimLeft(path, '/'))\n\t\tif cleanPath == \".\" {\n\t\t\tcleanPath = \"\"\n\t\t}\n\t\tinfo, err := fs.Stat(cfg.FS, cleanPath)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"stat %q: %w\", cleanPath, err)\n\t\t}\n\t\treturn info.Size(), nil\n\t}\n\n\tinfo, err := os.Stat(filepath.FromSlash(path))\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"stat %q: %w\", path, err)\n\t}\n\n\treturn info.Size(), nil\n}\n\n// SendStatus sets the HTTP status code and if the response body is empty,\n// it sets the correct status message in the body.\nfunc (r *DefaultRes) SendStatus(status int) error {\n\tr.Status(status)\n\n\tif statusDisallowsBody(status) {","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/res.go#L1157-L1193","documentation":"Returned by sendFileContentLength() when cfg.FS is set (embed.FS, os.DirFS, etc.) and fs.Stat fails on the cleaned path. This stat is only invoked for byte-range requests to compute Content-Length / handle 416 responses. The wrapped %w is the fs.FS error (typically fs.ErrNotExist or fs.ErrPermission).","triggerScenarios":"A request with a Range header arrives, SendFile.ByteRange is true, cfg.FS is set, and the file referenced is missing inside the FS, or the FS denies access (permission bit on an embed subtree, or a path that escapes the FS root after cleaning).","commonSituations":"Embed.FS does not include the requested file (//go:embed pattern too narrow); a Range request for a file removed between route registration and request; SendFile.ByteRange enabled but the FS root was mounted incorrectly; path traversal sanitized to empty after Clean.","solutions":["Verify the file exists inside the fs.FS by listing it at startup (fs.Stat(cfg.FS, path)) for the known asset set.","Widen the //go:embed directive to include all assets served via byte-range.","Confirm SendFile.FS is the same FS the routes were configured against.","If the error is intermittent, guard against concurrent deletion or regenerate the embed cache."],"exampleFix":"// before — embed pattern misses subdir\n//go:embed assets/*.png\nvar assets embed.FS\n// request for assets/icons/star.png -> stat \"assets/icons/star.png\": file does not exist\n\n// after\n//go:embed assets/**/*.png\nvar assets embed.FS","handlingStrategy":"validation","validationCode":"// At startup, verify every byte-range-served file exists in the FS.\nfunc verifyFS(fsroot fs.FS, files []string) error {\n    for _, f := range files {\n        if _, err := fs.Stat(fsroot, f); err != nil {\n            return fmt.Errorf(\"%s: %w\", f, err)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := c.Res().SendFile(path, fiber.SendFile{FS: assets, ByteRange: true}); err != nil {\n    if strings.Contains(err.Error(), \"stat\") {\n        return fiber.NewError(fiber.StatusNotFound, \"asset not found\")\n    }\n    return err\n}","preventionTips":["Widen //go:embed patterns to cover all served assets.","Run fs.WalkDir at startup to log the embedded file set.","Disable ByteRange on routes whose files are volatile."],"tags":["sendfile","filesystem","embed-fs","byte-range","stat"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}