caddyserver/caddy · error

can't parse line %d; line should be in KEY=VALUE format

Error message

can't parse line %d; line should be in KEY=VALUE format

What it means

parseEnvFile rejects a non-empty, non-comment line that contains no '=' separator (strings.Cut found no cut). Caddy's env-file format is strictly KEY=VALUE per line, unlike shell which also accepts bare `export KEY` declarations.

Source

Thrown at cmd/main.go:403

func parseEnvFile(envInput io.Reader) (map[string]string, error) {
	envMap := make(map[string]string)

	scanner := bufio.NewScanner(envInput)
	var lineNumber int

	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		lineNumber++

		// skip empty lines and lines starting with comment
		if line == "" || strings.HasPrefix(line, "#") {
			continue
		}

		// split line into key and value
		before, after, isCut := strings.Cut(line, "=")
		if !isCut {
			return nil, fmt.Errorf("can't parse line %d; line should be in KEY=VALUE format", lineNumber)
		}
		key, val := before, after

		// sometimes keys are prefixed by "export " so file can be sourced in bash; ignore it here
		key = strings.TrimPrefix(key, "export ")

		// validate key and value
		if key == "" {
			return nil, fmt.Errorf("missing or empty key on line %d", lineNumber)
		}
		if strings.Contains(key, " ") {
			return nil, fmt.Errorf("invalid key on line %d: contains whitespace: %s", lineNumber, key)
		}
		if strings.HasPrefix(val, " ") || strings.HasPrefix(val, "\t") {
			return nil, fmt.Errorf("invalid value on line %d: whitespace before value: '%s'", lineNumber, val)
		}

		// remove any trailing comment after value

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Go to the reported line number and either delete the line or convert it to KEY=VALUE
  2. Change `KEY: value` (YAML) to `KEY=value`
  3. Replace bare flags with explicit booleans: `ENABLE_TLS=true`
  4. Move shell directives (source, unset, if) out of the env file — Caddy only understands static assignments and an optional `export ` prefix

Example fix

# before (line 4)
LOGGING

# after
LOGGING=true
Defensive patterns

Strategy: validation

Validate before calling

grep -nE '^[^=#[:space:]][^=]*$' env && echo 'line(s) missing KEY=VALUE' || echo OK

Prevention

When it happens

Trigger: A line like `ENABLE_TLS` (boolean flag style), `KEY: value` (YAML style), `source other.env` (shell directive), or a continuation line of an unquoted multi-line value that lost its prefix.

Common situations: Adapting a docker-compose.yml environment block or Kubernetes ConfigMap (uses `KEY: value`), reusing a shell profile snippet, or a stray text line at the top of the file.

Related errors


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