{"record":{"id":"a156b3a834585d9a","repo":"caddyserver/caddy","slug":"invalid-key-on-line-d-contains-whitespace-s","errorCode":null,"errorMessage":"invalid key on line %d: contains whitespace: %s","messagePattern":"invalid key on line (.+?): contains whitespace: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/main.go","lineNumber":415,"sourceCode":"\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)\n\t\t\t\tif !scanner.Scan() {\n\t\t\t\t\tbreak\n\t\t\t\t}","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/main.go#L397-L433","documentation":"parseEnvFile rejects a key that contains a space after the `export ` prefix is trimmed. Note the check is only for ' ' (ASCII space) — but any space in a key makes it invalid as an environment variable name anyway. This differs from shells, which would try to execute such a line rather than export it.","triggerScenarios":"Lines like `MY KEY=value`, `export MY KEY=value`, or a key with a trailing space before '=' such as `KEY =value` (the space becomes part of the key).","commonSituations":"Writing `KEY = value` with spaces around '=' (common habit from YAML/INI files), descriptive names copied from docs ('API Key=...'), or a stray typo.","solutions":["Remove ALL spaces around '=' — write `KEY=value`, never `KEY = value`","Replace spaces in names with underscores: `API_KEY=...`","Quote the VALUE if it needs spaces: `KEY='my value'` (quoting is only supported on the value side)"],"exampleFix":"# before\nAPI KEY = abc123\n\n# after\nAPI_KEY=abc123","handlingStrategy":"validation","validationCode":"grep -nE '^[A-Za-z_][A-Za-z0-9_]*[[:space:]].*=|export [^=]*[[:space:]][^=]*=' env || echo OK","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write `KEY=value` with no spaces around '='","Use underscores, never spaces, in variable names"],"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"}