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
- Serve from a stable, low-mutation directory, or disable listing on volatile directories.
- Use embed.FS for immutable assets where Info() cannot fail after build.
- Treat the error as transient and retry the listing request, or log and skip — but note Echo currently returns the error rather than skipping.
- Ensure the process has consistent read access to all files in the listed directory.
Defensive patterns
Strategy: retry
Prevention
- Serve immutable embedded assets to eliminate Info() races.
- Don't enable directory listing on actively-mutated directories.
- If listing volatile dirs is unavoidable, retry the request on transient Info() failures.
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
- static middleware failed to read directory for listing: %w
- file does not implement io.ReadSeeker
- static middleware failed to create sub-filesystem: %w
- static middleware failed to create sub-filesystem from confi
- file does not implement io.ReadSeeker
AI-assisted analysis of labstack/echo@05489dc173 (2026-08-04).
Data as JSON: /data/errors/0f0b4023b67fc172.json.
Report an issue: GitHub.