{"record":{"id":"5baef0f329b8990e","repo":"caddyserver/caddy","slug":"can-t-parse-line-d-line-should-be-in-key-value-f","errorCode":null,"errorMessage":"can't parse line %d; line should be in KEY=VALUE format","messagePattern":"can't parse line (.+?); line should be in KEY=VALUE format","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/main.go","lineNumber":403,"sourceCode":"func parseEnvFile(envInput io.Reader) (map[string]string, error) {\n\tenvMap := make(map[string]string)\n\n\tscanner := bufio.NewScanner(envInput)\n\tvar lineNumber int\n\n\tfor scanner.Scan() {\n\t\tline := strings.TrimSpace(scanner.Text())\n\t\tlineNumber++\n\n\t\t// skip empty lines and lines starting with comment\n\t\tif line == \"\" || strings.HasPrefix(line, \"#\") {\n\t\t\tcontinue\n\t\t}\n\n\t\t// split line into key and value\n\t\tbefore, after, isCut := strings.Cut(line, \"=\")\n\t\tif !isCut {\n\t\t\treturn nil, fmt.Errorf(\"can't parse line %d; line should be in KEY=VALUE format\", lineNumber)\n\t\t}\n\t\tkey, val := before, after\n\n\t\t// sometimes keys are prefixed by \"export \" so file can be sourced in bash; ignore it here\n\t\tkey = strings.TrimPrefix(key, \"export \")\n\n\t\t// validate key and value\n\t\tif key == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"missing or empty key on line %d\", lineNumber)\n\t\t}\n\t\tif strings.Contains(key, \" \") {\n\t\t\treturn nil, fmt.Errorf(\"invalid key on line %d: contains whitespace: %s\", lineNumber, key)\n\t\t}\n\t\tif strings.HasPrefix(val, \" \") || strings.HasPrefix(val, \"\\t\") {\n\t\t\treturn nil, fmt.Errorf(\"invalid value on line %d: whitespace before value: '%s'\", lineNumber, val)\n\t\t}\n\n\t\t// remove any trailing comment after value","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/main.go#L385-L421","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Go to the reported line number and either delete the line or convert it to KEY=VALUE","Change `KEY: value` (YAML) to `KEY=value`","Replace bare flags with explicit booleans: `ENABLE_TLS=true`","Move shell directives (source, unset, if) out of the env file — Caddy only understands static assignments and an optional `export ` prefix"],"exampleFix":"# before (line 4)\nLOGGING\n\n# after\nLOGGING=true","handlingStrategy":"validation","validationCode":"grep -nE '^[^=#[:space:]][^=]*$' env && echo 'line(s) missing KEY=VALUE' || echo OK","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never put YAML (`KEY: value`) or bare flags in Caddy env files","Convert docker-compose/Kubernetes env blocks to KEY=value before reuse"],"tags":["caddy","env-file","parsing","configuration"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}