{"id":"0f0b4023b67fc172","repo":"labstack/echo","slug":"static-middleware-failed-to-get-file-info-for-list","errorCode":null,"errorMessage":"static middleware failed to get file info for listing: %w","messagePattern":"static middleware failed to get file info for listing: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"middleware/static.go","lineNumber":345,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"static middleware failed to read directory for listing: %w\", err)\n\t}\n\n\t// Create directory index\n\tres.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)\n\tdata := struct {\n\t\tName  string\n\t\tFiles []any\n\t}{\n\t\tName: pathInFs,\n\t}\n\n\tfor _, f := range files {\n\t\tvar size int64\n\t\tif !f.IsDir() {\n\t\t\tinfo, err := f.Info()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"static middleware failed to get file info for listing: %w\", err)\n\t\t\t}\n\t\t\tsize = info.Size()\n\t\t}\n\n\t\tdata.Files = append(data.Files, struct {\n\t\t\tName string\n\t\t\tDir  bool\n\t\t\tSize string\n\t\t}{f.Name(), f.IsDir(), format(size)})\n\t}\n\n\treturn t.Execute(res, data)\n}\n\n// format formats bytes integer to human readable string.\n// For example, 31323 bytes will return 30.59KB.\nfunc format(b int64) string {\n\tmultiple := \"\"","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/middleware/static.go#L327-L363","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["static","filesystem","directory-listing","runtime","race"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}