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

  1. Enable index generation (fasthttp.Fs.GenerateIndexPages = true) if listings are desired
  2. Provide a static index file and register it via IndexNames so no generation is needed
  3. Disable directory browsing intentionally and return 403/404 for directory URLs by handling the error yourself
  4. 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

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


AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31). Data as JSON: /api/errors/f668b701f87f59b6. Report an issue: GitHub.