gofiber/fiber · error

failed to determine abs file path: %w

Error message

failed to determine abs file path: %w

What it means

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

Source

Thrown at res.go:939

	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 9a4c7e57fe)

Solutions

  1. Pass an absolute path to SendFile, or set the FS / Views root to a stable location.
  2. Ensure the process working directory exists and is readable for the process lifetime.
  3. Set WorkingDirectory in your systemd unit / container to a stable path.

Example fix

// before
c.SendFile("./static/index.html") // fails if cwd is gone

// after
abs, _ := filepath.Abs("./static/index.html")
c.SendFile(abs)
// or embed: c.SendFile("index.html", fiber.Config{ FS: embedFS })
Defensive patterns

Strategy: validation

Validate before calling

// resolve once at startup so cwd problems surface before serving
var staticRoot string
func init() {
    var err error
    staticRoot, err = filepath.Abs("./static")
    if err != nil { log.Fatalf("static root: %v", err) }
}

Try / catch

if err := c.SendFile(file); err != nil {
    if strings.Contains(err.Error(), "abs file path") {
        log.Errorf("cwd unavailable; cannot resolve %s", file)
        return fiber.ErrInternalServerError
    }
    return c.Status(fiber.StatusNotFound).SendString("not found")
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/3bce6b9f5c512c42.json. Report an issue: GitHub.