caddyserver/caddy · error
invalid precompressed flag
Error message
invalid precompressed flag: %v
What it means
Wrapper in the `caddy file-server` command for fs.GetStringSlice("precompressed") failure: the --precompressed flag could not be parsed as a string slice (malformed flag usage). The faulty input is the --precompressed flag value, e.g. a badly formed list.
Solutions
- Pass a clean comma-separated list: caddy file-server --precompressed gzip zstd (repeatable) or --precompressed=gzip,zstd
- Check the shell script for empty tokens or stray quotes
- 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: try-catch
Validate before calling
# normalize flags before invoking precompressed=$(echo "$PRECOMPRESSED" | tr ',' '\n' | sed '/^$/d' | paste -sd, -)
Prevention
- Keep comma lists free of empty tokens
- Wrap the CLI in a script that validates flags
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
- getting module named
- invalid header flag
- module is not a precompressor; is %T
- at least one package name must be specified
- cannot read etag from file
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/71a610ffe01db13b.
Report an issue: GitHub.
Appendix: 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)