labstack/echo · warning

static middleware failed to get file info for listing: %w

Error message

static middleware failed to get file info for listing: %w

What it means

Returned by listDir() (static.go:345) when f.Info() fails for one of the entries returned by fs.ReadDir while building a directory listing. fs.DirEntry.Info() can fail if the underlying file was removed or became inaccessible between the ReadDir and the Info call. The size is only fetched for non-directory entries.

Source

Thrown at middleware/static.go:345

	if err != nil {
		return fmt.Errorf("static middleware failed to read directory for listing: %w", err)
	}

	// Create directory index
	res.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
	data := struct {
		Name  string
		Files []any
	}{
		Name: pathInFs,
	}

	for _, f := range files {
		var size int64
		if !f.IsDir() {
			info, err := f.Info()
			if err != nil {
				return fmt.Errorf("static middleware failed to get file info for listing: %w", err)
			}
			size = info.Size()
		}

		data.Files = append(data.Files, struct {
			Name string
			Dir  bool
			Size string
		}{f.Name(), f.IsDir(), format(size)})
	}

	return t.Execute(res, data)
}

// format formats bytes integer to human readable string.
// For example, 31323 bytes will return 30.59KB.
func format(b int64) string {
	multiple := ""

View on GitHub (pinned to 05489dc173)

Solutions

  1. Serve from a stable, low-mutation directory, or disable listing on volatile directories.
  2. Use embed.FS for immutable assets where Info() cannot fail after build.
  3. Treat the error as transient and retry the listing request, or log and skip — but note Echo currently returns the error rather than skipping.
  4. Ensure the process has consistent read access to all files in the listed directory.
Defensive patterns

Strategy: retry

Prevention

When it happens

Trigger: During directory listing generation, for each file entry Echo calls f.Info() to read Size(); if the file is deleted, renamed, or its metadata becomes unreadable in that window, Info() returns an error that gets wrapped here.

Common situations: A log or temp directory being actively written/deleted while a listing request runs; NFS/network filesystems with eventual consistency; concurrent processes modifying the directory.

Related errors


AI-assisted analysis of labstack/echo@05489dc173 (2026-08-04). Data as JSON: /data/errors/0f0b4023b67fc172.json. Report an issue: GitHub.