caddyserver/caddy · error

invalid precompressed flag: %v

Error message

invalid precompressed flag: %v

What it means

`caddy file-server` CLI startup error: the --precompressed flag could not be parsed as a string slice. The wrapped error comes from the flag parser (pflag) when the value is malformed.

Source

Thrown at modules/caddyhttp/fileserver/command.go:101

	})
}

func cmdFileServer(fs caddycmd.Flags) (int, error) {
	caddy.TrapSignals()

	domain := fs.String("domain")
	root := fs.String("root")
	listen := fs.String("listen")
	browse := fs.Bool("browse")
	templates := fs.Bool("templates")
	accessLog := fs.Bool("access-log")
	fileLimit := fs.Int("file-limit")
	debug := fs.Bool("debug")
	revealSymlinks := fs.Bool("reveal-symlinks")
	compress := !fs.Bool("no-compress")
	precompressed, err := fs.GetStringSlice("precompressed")
	if err != nil {
		return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid precompressed flag: %v", err)
	}
	var handlers []json.RawMessage

	if compress {
		zstd, err := caddy.GetModule("http.encoders.zstd")
		if err != nil {
			return caddy.ExitCodeFailedStartup, err
		}

		gzip, err := caddy.GetModule("http.encoders.gzip")
		if err != nil {
			return caddy.ExitCodeFailedStartup, err
		}

		handlers = append(handlers, caddyconfig.JSONModuleObject(encode.Encode{
			EncodingsRaw: caddy.ModuleMap{
				"zstd": caddyconfig.JSON(zstd.New(), nil),
				"gzip": caddyconfig.JSON(gzip.New(), nil),

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Pass a clean comma-separated list: caddy file-server --precompressed gzip zstd (repeatable) or --precompressed=gzip,zstd
  2. Check the shell script for empty tokens or stray quotes
  3. Validate arguments before invoking the command in automation

Example fix

# before
caddy file-server --precompressed "gzip,,zstd"
# after
caddy file-server --precompressed gzip,zstd
Defensive patterns

Strategy: validation

Validate before calling

# normalize flags before invoking
precompressed=$(echo "$PRECOMPRESSED" | tr ',' '\n' | sed '/^$/d' | paste -sd, -)

Prevention

When it happens

Trigger: Passing --precompressed with an invalid list form, e.g. --precompressed= (empty with bad splitting) or quoting oddities that make fs.GetStringSlice("precompressed") fail.

Common situations: Shell scripts with unquoted or malformed comma lists: --precompressed gzip,,zstd; wrapper scripts mangling arguments.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/71a610ffe01db13b. Report an issue: GitHub.