{"record":{"id":"3bce6b9f5c512c42","repo":"gofiber/fiber","slug":"failed-to-determine-abs-file-path-w","errorCode":null,"errorMessage":"failed to determine abs file path: %w","messagePattern":"failed to determine abs file path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"res.go","lineNumber":1091,"sourceCode":"\tr.c.pathOriginal = utils.CopyString(r.c.pathOriginal)\n\n\trequest := &r.c.fasthttp.Request\n\n\t// Delete the Accept-Encoding header if compression is disabled\n\tif !cfg.Compress {\n\t\t// https://github.com/valyala/fasthttp/blob/7cc6f4c513f9e0d3686142e0a1a5aa2f76b3194a/fs.go#L55\n\t\trequest.Header.Del(HeaderAcceptEncoding)\n\t}\n\n\t// copy of https://github.com/valyala/fasthttp/blob/7cc6f4c513f9e0d3686142e0a1a5aa2f76b3194a/fs.go#L103-L121 with small adjustments\n\tif file == \"\" || (!filepath.IsAbs(file) && cfg.FS == nil) {\n\t\t// extend relative path to absolute path\n\t\thasTrailingSlash := file != \"\" && (file[len(file)-1] == '/' || file[len(file)-1] == '\\\\')\n\n\t\tvar err error\n\t\tfile = filepath.FromSlash(file)\n\t\tif file, err = filepath.Abs(file); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to determine abs file path: %w\", err)\n\t\t}\n\t\tif hasTrailingSlash {\n\t\t\tfile += \"/\"\n\t\t}\n\t}\n\n\t// convert the path to forward slashes regardless the OS in order to set the URI properly\n\t// the handler will convert back to OS path separator before opening the file\n\tfile = filepath.ToSlash(file)\n\n\t// Restore the original requested URL\n\toriginalURL := utils.CopyString(r.c.OriginalURL())\n\tdefer request.SetRequestURI(originalURL)\n\n\t// Set new URI for fileHandler\n\trequest.SetRequestURI(file)\n\n\tvar (","sourceCodeStart":1073,"sourceCodeEnd":1109,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/res.go#L1073-L1109","documentation":"Returned by SendFile/SendFileBypass when the file argument is empty or relative and no FS is configured, so Fiber calls filepath.Abs() to resolve the working-directory-relative path. filepath.Abs only fails when the OS cannot return the current working directory (e.g., the process's cwd was deleted underneath it).","triggerScenarios":"Calling res.SendFile(path) where path is relative (or empty), cfg.FS is nil, and filepath.Abs() returns an error — practically only when the process's current working directory has been removed while the process runs, or on a platform where getcwd fails.","commonSituations":"Process started in a directory that was later `rm -rf`'d or replaced; container restart with a vanished mount used as cwd; very rare on normal server lifecycles. Almost always a symptom of a broken deployment rather than an application bug.","solutions":["Pass an absolute path to SendFile to skip the filepath.Abs resolution entirely.","Provide Config.SendFile.FS (e.g., os.DirFS(root)) so Fiber resolves against the FS instead of the cwd.","Restart the process from a stable working directory that is not deleted at runtime.","If using containers, ensure the cwd mount persists for the process lifetime."],"exampleFix":"// before — relative path, cwd deleted at runtime\nreturn c.Res().SendFile(\"./assets/logo.png\")\n// -> failed to determine abs file path: getwd: no such file or directory\n\n// after — absolute path or os.DirFS\nreturn c.Res().SendFile(\"/srv/app/assets/logo.png\")\n// or configure once:\napp := fiber.New(fiber.Config{})\n// use the FS-aware overload with an os.DirFS root","handlingStrategy":"validation","validationCode":"// Resolve to absolute at startup; use an FS to avoid cwd dependence.\nabs, err := filepath.Abs(assetRoot)\nif err != nil { log.Fatal(err) }\n// Prefer FS-based serving to skip filepath.Abs entirely.\nfs := os.DirFS(abs)","typeGuard":null,"tryCatchPattern":"if err := c.Res().SendFile(path, cfg); err != nil {\n    if strings.Contains(err.Error(), \"failed to determine abs file path\") {\n        log.Fatal(\"working directory unavailable; restart in a stable cwd\")\n    }\n    return err\n}","preventionTips":["Use absolute paths or an os.DirFS for SendFile.","Do not delete the process's cwd while it runs.","In containers, mount the cwd volume for the process lifetime."],"tags":["sendfile","filesystem","path-resolution","deployment"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}