valyala/fasthttp · warning
no 'create file' permissions
Error message
no 'create file' permissions
What it means
errNoCreatePermission indicates the handler is not permitted to create files — specifically the auto-generated directory index — because CreateIndexPages (or equivalent permission) is disabled. fasthttp refuses to write generated content to disk in this configuration.
Source
Thrown at fs.go:1565
"Allow write access to the directory with this file in order to improve fasthttp performance", indexFilePath)
mustCompress = false
return h.openFSFile(indexFilePath, mustCompress, fileEncoding)
}
if !errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("cannot open file %q: %w", indexFilePath, err)
}
}
if !h.generateIndexPages {
return nil, fmt.Errorf("cannot access directory without index page: directory %q", dirPath)
}
return h.createDirIndex(ctx, dirPath, mustCompress, fileEncoding)
}
var (
errDirIndexRequired = errors.New("directory index required")
errNoCreatePermission = errors.New("no 'create file' permissions")
)
func (h *fsHandler) createDirIndex(ctx *RequestCtx, dirPath string, mustCompress bool, fileEncoding string) (*fsFile, error) {
w := &bytebufferpool.ByteBuffer{}
base := ctx.URI()
// io/fs doesn't support ReadDir with empty path.
if dirPath == "" {
dirPath = "."
}
basePathEscaped := html.EscapeString(string(base.Path()))
_, _ = fmt.Fprintf(w, "<html><head><title>%s</title><style>.dir { font-weight: bold }</style></head><body>", basePathEscaped)
_, _ = fmt.Fprintf(w, "<h1>%s</h1>", basePathEscaped)
_, _ = fmt.Fprintf(w, "<ul>")
if len(basePathEscaped) > 1 {View on GitHub (pinned to c96f600972)
Solutions
- Enable index generation (fasthttp.Fs.GenerateIndexPages = true) if listings are desired
- Provide a static index file and register it via IndexNames so no generation is needed
- Disable directory browsing intentionally and return 403/404 for directory URLs by handling the error yourself
- Serve an explicit file path instead of a directory
Example fix
// before
fsHandler := h.fs.NewRequestHandler() // GenerateIndexPages=false, dir request -> refusal
// after
h.fs.GenerateIndexPages = true
// or: h.fs.IndexNames = []string{"index.html"} Defensive patterns
Strategy: validation
Validate before calling
if !h.fs.GenerateIndexPages && len(h.fs.IndexNames) == 0 {
// directory requests will be refused; register an index or enable generation
} Try / catch
if err != nil && strings.Contains(err.Error(), "create file") {
ctx.Error("directory listing not available", fasthttp.StatusForbidden)
} Prevention
- Enable GenerateIndexPages only on writable, trusted roots
- Prefer static index files over on-the-fly generation in production
- Decide explicitly whether directory browsing is allowed and encode it in config
- Check filesystem write permissions for the fasthttp process when generation is on
When it happens
Trigger: A directory request requires building/caching a directory index, but the fsHandler is configured without permission to create the index file (index generation disabled), so this sentinel is returned.
Common situations: Production configs with GenerateIndexPages=false where clients request bare directory URLs; deploying read-only static servers and expecting listings; typos in IndexNames leaving no index file to serve.
Related errors
- must implement readat
- directory index required
- cannot open file %q: %w
- cannot create temporary file for %q: %w
- must implement seek
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/f668b701f87f59b6.
Report an issue: GitHub.