caddyserver/caddy · error
cannot adapt config without config file (use --config)
Error message
cannot adapt config without config file (use --config)
What it means
loadConfigWithLogger rejects the combination --adapter <name> with no --config: an adapter only transforms file content, so naming one without input is ambiguous. It points you at --config explicitly because stdin alone ('-') also requires being named via --config -.
Source
Thrown at cmd/main.go:155
// adapter is not empty,
// adapter is not "caddyfile",
// extension is not ".json",
// extension is not ".caddyfile"
// file does not start with "Caddyfile"
return false, nil
}
func loadConfigWithLogger(logger *zap.Logger, configFile, adapterName string) ([]byte, string, string, error) {
// if no logger is provided, use a nop logger
// just so we don't have to check for nil
if logger == nil {
logger = zap.NewNop()
}
// specifying an adapter without a config file is ambiguous
if adapterName != "" && configFile == "" {
return nil, "", "", fmt.Errorf("cannot adapt config without config file (use --config)")
}
// load initial config and adapter
var config []byte
var cfgAdapter caddyconfig.Adapter
var err error
if configFile != "" {
if configFile == "-" {
config, err = io.ReadAll(os.Stdin)
if err != nil {
return nil, "", "", fmt.Errorf("reading config from stdin: %v", err)
}
logger.Info("using config from stdin")
} else {
config, err = os.ReadFile(configFile)
if err != nil {
return nil, "", "", fmt.Errorf("reading config from file: %v", err)
}View on GitHub (pinned to 50e54ee279)
Solutions
- Add --config with a path, or --config - to read stdin
Example fix
# before caddy adapt --adapter caddyfile # after caddy adapt --config Caddyfile --adapter caddyfile cat Caddyfile | caddy adapt --config - --adapter caddyfile
Defensive patterns
Strategy: validation
Validate before calling
if adapterName != "" && configFile == "" { return errors.New("--adapter requires --config (use '--config -' for stdin)") } Prevention
- Treat --adapter and --config as a pair
- Use '--config -' explicitly for stdin
When it happens
Trigger: Running 'caddy adapt --adapter caddyfile' with no --config; piping a config to stdin but forgetting --config -; 'caddy run --adapter json' with no file.
Common situations: Users assuming the adapter flag implies reading stdin; copy-pasted commands that dropped the --config part.
Related errors
- adapting config using %s: %v
- invalid admin address %s: %v
- caddy responded with error: HTTP %d: %s
- no config file to load; either use --config flag or ensure C
- unmarshaling admin listener address from config: %v
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/a6f273180a888c38.
Report an issue: GitHub.