{"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":939,"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":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/res.go#L921-L957","documentation":"Thrown while serving a file (SendFile path) when converting a relative path to absolute fails. filepath.Abs only fails if os.Getwd() fails - the process's current working directory cannot be determined (deleted, permission revoked, or unset in a sandboxed runtime).","triggerScenarios":"Calling c.SendFile(\"relative/path\") (relative path, no FS) after the process's working directory was removed or became inaccessible; or a container/runtime that does not provide a cwd.","commonSituations":"Process started in a directory later deleted; chdir to a removed path; restricted container runtimes with no cwd; os.Getwd permission error; systemd units without WorkingDirectory.","solutions":["Pass an absolute path to SendFile, or set the FS / Views root to a stable location.","Ensure the process working directory exists and is readable for the process lifetime.","Set WorkingDirectory in your systemd unit / container to a stable path."],"exampleFix":"// before\nc.SendFile(\"./static/index.html\") // fails if cwd is gone\n\n// after\nabs, _ := filepath.Abs(\"./static/index.html\")\nc.SendFile(abs)\n// or embed: c.SendFile(\"index.html\", fiber.Config{ FS: embedFS })","handlingStrategy":"validation","validationCode":"// resolve once at startup so cwd problems surface before serving\nvar staticRoot string\nfunc init() {\n    var err error\n    staticRoot, err = filepath.Abs(\"./static\")\n    if err != nil { log.Fatalf(\"static root: %v\", err) }\n}","typeGuard":null,"tryCatchPattern":"if err := c.SendFile(file); err != nil {\n    if strings.Contains(err.Error(), \"abs file path\") {\n        log.Errorf(\"cwd unavailable; cannot resolve %s\", file)\n        return fiber.ErrInternalServerError\n    }\n    return c.Status(fiber.StatusNotFound).SendString(\"not found\")\n}","preventionTips":["Prefer absolute paths or go:embed FS for static assets.","Pin WorkingDirectory in deployment units.","Fail fast on os.Getwd errors at startup."],"tags":["filesystem","sendfile","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}