{"record":{"id":"13987e310136196b","repo":"docker/cli","slug":"no-variable-name-on-line-s","errorCode":null,"errorMessage":"no variable name on line '%s'","messagePattern":"no variable name on line '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kvfile/kvfile.go","lineNumber":105,"sourceCode":"\t\tif !utf8.Valid(scannedBytes) {\n\t\t\treturn []string{}, fmt.Errorf(\"invalid utf8 bytes at line %d: %v\", currentLine, scannedBytes)\n\t\t}\n\t\t// We trim UTF8 BOM\n\t\tif currentLine == 1 {\n\t\t\tscannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom)\n\t\t}\n\t\t// trim the line from all leading whitespace first. trailing whitespace\n\t\t// is part of the value, and is kept unmodified.\n\t\tline := strings.TrimLeftFunc(string(scannedBytes), unicode.IsSpace)\n\n\t\tif len(line) == 0 || line[0] == '#' {\n\t\t\t// skip empty lines and comments (lines starting with '#')\n\t\t\tcontinue\n\t\t}\n\n\t\tkey, _, hasValue := strings.Cut(line, \"=\")\n\t\tif len(key) == 0 {\n\t\t\treturn []string{}, fmt.Errorf(\"no variable name on line '%s'\", line)\n\t\t}\n\n\t\t// leading whitespace was already removed from the line, but\n\t\t// variables are not allowed to contain whitespace or have\n\t\t// trailing whitespace.\n\t\tif strings.ContainsAny(key, whiteSpaces) {\n\t\t\treturn []string{}, fmt.Errorf(\"variable '%s' contains whitespaces\", key)\n\t\t}\n\n\t\tif hasValue {\n\t\t\t// key/value pair is valid and has a value; add the line as-is.\n\t\t\tlines = append(lines, line)\n\t\t\tcontinue\n\t\t}\n\n\t\tif lookupFn != nil {\n\t\t\t// No value given; try to look up the value. The value may be\n\t\t\t// empty but if no value is found, the key is omitted.","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/pkg/kvfile/kvfile.go#L87-L123","documentation":"Returned inside parseKeyValueFile for a non-comment, non-empty line whose key (text before the first '=') is empty — i.e. the line starts with '='. kvfile splits on the first '=' and requires a non-empty KEY.","triggerScenarios":"An --env-file line such as '=value' or '=foo' (nothing before the '='), typically from a typo, a malformed generated file, or an env var whose name was stripped during templating.","commonSituations":"Template/substitution that produced an empty variable name (e.g. '${EMPTY}=x'), a hand-edited file where the key was deleted but '=' left behind, or a misformatted CSV export.","solutions":["Add a non-empty variable name before '=': 'MYVAR=value'.","If the line is meant to be a comment, prefix it with '#'.","Audit templating that produces env files to guarantee a non-empty key."],"exampleFix":"# before (=value)\n=postgres://db\n# after\nDATABASE_URL=postgres://db","handlingStrategy":"validation","validationCode":"// Scan for lines that start with '=' (empty key) before kvfile.Parse.\nimport (\"bufio\"; \"os\"; \"strings\")\n\nfunc noEmptyKeys(name string) error {\n    f, err := os.Open(name)\n    if err != nil { return err }\n    defer f.Close()\n    s := bufio.NewScanner(f)\n    for ln := 1; s.Scan(); ln++ {\n        t := strings.TrimLeft(s.Text(), \" \\t\")\n        if t == \"\" || strings.HasPrefix(t, \"#\") { continue }\n        if strings.HasPrefix(t, \"=\") {\n            return fmt.Errorf(\"%s:%d: no variable name on line %q\", name, ln, t)\n        }\n    }\n    return s.Err()\n}\n\n// if err := noEmptyKeys(file); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if _, err := kvfile.Parse(file, nil); err != nil {\n    return err // invalid env file (<file>): no variable name on line '...'\n}","preventionTips":["Ensure every KEY=value line has a non-empty KEY.","Prefix genuine comments with '#'.","Lint generated env files for empty keys in CI."],"tags":["docker","env-file","kvfile","parsing","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}