{"record":{"id":"5dab31ba64a9f740","repo":"sipeed/picoclaw","slug":"invalid-format-at-line-d-s","errorCode":null,"errorMessage":"invalid format at line %d: %s","messagePattern":"invalid format at line (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/mcp/manager.go","lineNumber":91,"sourceCode":"\tdefer file.Close()\n\n\tenvVars := make(map[string]string)\n\tscanner := bufio.NewScanner(file)\n\tlineNum := 0\n\n\tfor scanner.Scan() {\n\t\tlineNum++\n\t\tline := strings.TrimSpace(scanner.Text())\n\n\t\t// Skip empty lines and comments\n\t\tif line == \"\" || strings.HasPrefix(line, \"#\") {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Parse KEY=value\n\t\tparts := strings.SplitN(line, \"=\", 2)\n\t\tif len(parts) != 2 {\n\t\t\treturn nil, fmt.Errorf(\"invalid format at line %d: %s\", lineNum, line)\n\t\t}\n\n\t\tkey := strings.TrimSpace(parts[0])\n\t\tvalue := strings.TrimSpace(parts[1])\n\n\t\tif key == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"invalid format at line %d: empty key\", lineNum)\n\t\t}\n\n\t\t// Remove surrounding quotes if present\n\t\tif len(value) >= 2 {\n\t\t\tif (value[0] == '\"' && value[len(value)-1] == '\"') ||\n\t\t\t\t(value[0] == '\\'' && value[len(value)-1] == '\\'') {\n\t\t\t\tvalue = value[1 : len(value)-1]\n\t\t\t}\n\t\t}\n\n\t\tenvVars[key] = value","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/mcp/manager.go#L73-L109","documentation":"loadEnvFile parses each non-empty, non-comment line as KEY=value via strings.SplitN(line, \"=\", 2); a line without any '=' character is invalid and this error reports its 1-based line number and full content. Parsing stops at the first bad line, so earlier lines are discarded — the whole env file load fails.","triggerScenarios":"Lines like FOO (bare key), export FOO is fine only if it contains '=', but shell directives like source ~/.bashrc, set -e, or plain prose notes (not prefixed with #) all lack '=' and fail; a commented line whose leading # was lost (inline comments after values are kept as part of the value and are fine); a line-continuation backslash from a shell script pasted in.","commonSituations":"Pasting snippets from .bashrc into the env file; documenting entries with a bare word (FOO — the key) instead of FOO=; generated files where a value wrapped onto its own line; forgetting that only lines starting with # are comments.","solutions":["Fix the reported line: give every entry the KEY=value form","Prefix explanatory notes with # so they are treated as comments","Remove shell syntax (source, export-without-=, set) — this is a plain env file, not a script","Re-run: the message names the exact line number, so iterate until parsing passes"],"exampleFix":"# before (.env line 3 fails)\n# myserver config\nDB_HOST=localhost\nsecret key goes here\n\n# after\n# myserver config\nDB_HOST=localhost\nSECRET_KEY=...","handlingStrategy":"type-guard","validationCode":"func lintEnvFile(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil {\n        return err\n    }\n    for i, line := range strings.Split(string(data), \"\\n\") {\n        line = strings.TrimSpace(line)\n        if line == \"\" || strings.HasPrefix(line, \"#\") {\n            continue\n        }\n        if !validEnvLine(line) {\n            return fmt.Errorf(\"line %d lacks KEY=value form: %s\", i+1, line)\n        }\n    }\n    return nil\n}","typeGuard":"func validEnvLine(line string) bool {\n    key, value, found := strings.Cut(line, \"=\")\n    return found && strings.TrimSpace(key) != \"\"\n}","tryCatchPattern":null,"preventionTips":["Lint env files in CI with a KEY=value parser before they ship","Keep shell snippets out of env files — only # comments and KEY=value lines are supported","Quote whole values with matching quotes only when needed; values may contain '=' but every line needs one"],"tags":["mcp","config","env-file","parsing"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}