caddyserver/caddy · error

reading config from stdin: %v

Error message

reading config from stdin: %v

What it means

The special config path '-' makes Caddy read the config from stdin, and this wraps an io.ReadAll(os.Stdin) failure. The pipe/stdin could not be read — broken pipe, closed stdin, or an OS-level read error.

Source

Thrown at cmd/main.go:166

	// 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)
			}
			logger.Info("using config from file", zap.String("file", configFile))
		}
	} else if adapterName == "" {
		// if the Caddyfile adapter is plugged in, we can try using an
		// adjacent Caddyfile by default
		cfgAdapter = caddyconfig.GetAdapter("caddyfile")
		if cfgAdapter != nil {
			config, err = os.ReadFile("Caddyfile")
			if errors.Is(err, fs.ErrNotExist) {
				// okay, no default Caddyfile; pretend like this never happened
				cfgAdapter = nil

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Ensure something feeds stdin: cat config | caddy run --config -
  2. In service units, set StandardInput=file:/path or just use --config with a real path
  3. Verify the producer of the pipe succeeded before piping into caddy

Example fix

# before (systemd unit, stdin not wired)
ExecStart=/usr/bin/caddy run --config -

# after
ExecStart=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
Defensive patterns

Strategy: validation

Validate before calling

# Confirm stdin is wired before using '--config -':
if [ -t 0 ]; then echo "refusing to read config from a terminal" >&2; exit 1; fi
cat Caddyfile | caddy adapt --config - --adapter caddyfile

Prevention

When it happens

Trigger: Running 'caddy run --config -' with stdin closed (no redirect in a cron/systemd unit), or an upstream producer of the pipe exiting mid-write.

Common situations: Systemd units without StandardInput=pipe; scripts where the generating command failed so the pipe delivered EOF/error; interactive shells where the command appears to hang then error.

Related errors


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