gofiber/fiber · error

failed to determine abs file path

Error message

failed to determine abs file path: %w

What it means

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).

Solutions

  1. Pass an absolute path to SendFile to skip the filepath.Abs resolution entirely.
  2. Provide Config.SendFile.FS (e.g., os.DirFS(root)) so Fiber resolves against the FS instead of the cwd.
  3. Restart the process from a stable working directory that is not deleted at runtime.
  4. If using containers, ensure the cwd mount persists for the process lifetime.

Example fix

// before — relative path, cwd deleted at runtime
return c.Res().SendFile("./assets/logo.png")
// -> failed to determine abs file path: getwd: no such file or directory

// after — absolute path or os.DirFS
return c.Res().SendFile("/srv/app/assets/logo.png")
// or configure once:
app := fiber.New(fiber.Config{})
// use the FS-aware overload with an os.DirFS root
Defensive patterns

Strategy: validation

Validate before calling

// Resolve to absolute at startup; use an FS to avoid cwd dependence.
abs, err := filepath.Abs(assetRoot)
if err != nil { log.Fatal(err) }
// Prefer FS-based serving to skip filepath.Abs entirely.
fs := os.DirFS(abs)

Try / catch

if err := c.Res().SendFile(path, cfg); err != nil {
    if strings.Contains(err.Error(), "failed to determine abs file path") {
        log.Fatal("working directory unavailable; restart in a stable cwd")
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/3bce6b9f5c512c42. Report an issue: GitHub.

Appendix: source

Thrown at res.go:1091

	r.c.pathOriginal = utils.CopyString(r.c.pathOriginal)

	request := &r.c.fasthttp.Request

	// Delete the Accept-Encoding header if compression is disabled
	if !cfg.Compress {
		// https://github.com/valyala/fasthttp/blob/7cc6f4c513f9e0d3686142e0a1a5aa2f76b3194a/fs.go#L55
		request.Header.Del(HeaderAcceptEncoding)
	}

	// copy of https://github.com/valyala/fasthttp/blob/7cc6f4c513f9e0d3686142e0a1a5aa2f76b3194a/fs.go#L103-L121 with small adjustments
	if file == "" || (!filepath.IsAbs(file) && cfg.FS == nil) {
		// extend relative path to absolute path
		hasTrailingSlash := file != "" && (file[len(file)-1] == '/' || file[len(file)-1] == '\\')

		var err error
		file = filepath.FromSlash(file)
		if file, err = filepath.Abs(file); err != nil {
			return fmt.Errorf("failed to determine abs file path: %w", err)
		}
		if hasTrailingSlash {
			file += "/"
		}
	}

	// convert the path to forward slashes regardless the OS in order to set the URI properly
	// the handler will convert back to OS path separator before opening the file
	file = filepath.ToSlash(file)

	// Restore the original requested URL
	originalURL := utils.CopyString(r.c.OriginalURL())
	defer request.SetRequestURI(originalURL)

	// Set new URI for fileHandler
	request.SetRequestURI(file)

	var (

View on GitHub (pinned to a105acad6c)