{"record":{"id":"516974a9e9c3a0a4","repo":"caddyserver/caddy","slug":"missing-or-empty-key-on-line-d","errorCode":null,"errorMessage":"missing or empty key on line %d","messagePattern":"missing or empty key on line (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/main.go","lineNumber":412,"sourceCode":"\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\n\t\tif commentStart, _, found := strings.Cut(val, \"#\"); found {\n\t\t\tval = strings.TrimRight(commentStart, \" \\t\")\n\t\t}\n\n\t\t// quoted value: support newlines\n\t\tif strings.HasPrefix(val, `\"`) || strings.HasPrefix(val, \"'\") {\n\t\t\tquote := string(val[0])\n\t\t\tfor !strings.HasSuffix(line, quote) || strings.HasSuffix(line, `\\`+quote) {\n\t\t\t\tval = strings.ReplaceAll(val, `\\`+quote, quote)","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/main.go#L394-L430","documentation":"parseEnvFile rejects a line whose key is empty after splitting on '=' and stripping an optional `export ` prefix. That means the line starts with '=' (value with no key), or is exactly `export` with nothing after it.","triggerScenarios":"A line like `=value`, `=` alone, or `export ` followed by `=something` with the variable name missing (e.g. a failed sed/edit leaving `export =foo`).","commonSituations":"Template substitution that produced an empty variable name (`${}=value`), hand-editing accidents, or find-replace that deleted the key but left the '=' and value.","solutions":["Inspect the reported line and restore the missing key name before the '='","Delete stray `=` or `=`+value lines","If the line came from a template, fix the template variable so it renders an actual key"],"exampleFix":"# before (line 2)\n=DEBUG\n\n# after\nLOG_LEVEL=DEBUG","handlingStrategy":"validation","validationCode":"grep -nE '^(export )?=' env && echo 'empty key line(s) found' || echo OK","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit templated env files for unset variable names rendering as empty keys"],"tags":["caddy","env-file","parsing","configuration"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}