{"record":{"id":"e21acedf78b97752","repo":"gotify/server","slug":"invalid-csv-for-s-q-w","errorCode":null,"errorMessage":"invalid CSV for %s (%q): %w","messagePattern":"invalid CSV for (.+?) \\(%q\\): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/parse.go","lineNumber":87,"sourceCode":"\nfunc parseList(target *[]string, env string) error {\n\traw, ok, err := lookupEnv(env)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !ok {\n\t\treturn nil\n\t}\n\tif raw == \"\" {\n\t\t*target = []string{}\n\t\treturn nil\n\t}\n\treader := csv.NewReader(strings.NewReader(raw))\n\treader.TrimLeadingSpace = true\n\treader.LazyQuotes = true\n\trecord, err := reader.Read()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid CSV for %s (%q): %w\", env, raw, err)\n\t}\n\t*target = record\n\treturn nil\n}\n\nfunc parseMap(target *map[string]string, env string) error {\n\traw, ok, err := lookupEnv(env)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !ok || raw == \"\" {\n\t\treturn nil\n\t}\n\tout := map[string]string{}\n\tif err := json.Unmarshal([]byte(raw), &out); err != nil {\n\t\treturn fmt.Errorf(\"invalid JSON for %s: %w\", env, err)\n\t}\n\t*target = out","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/gotify/server/blob/14bfc256276775c425f988d621dccfe705de18ac/config/parse.go#L69-L105","documentation":"parseList parses the env value as a single CSV record using encoding/csv (TrimLeadingSpace and LazyQuotes enabled). If csv.Reader.Read fails — unbalanced quotes, an odd quote in the middle of a field — the error is wrapped as 'invalid CSV for %s (%q): %w'.","triggerScenarios":"Calling config.Get with a list-typed env var whose value has malformed CSV quoting, e.g. ALLOWED_HOSTS='a.com,\"b.com' (unclosed quote) or an embedded quote that even LazyQuotes cannot reconcile.","commonSituations":"Values like \"a,b,c\" wrapped in literal double quotes by the shell/CI so csv sees stray quotes, JSON arrays ('[\"a\",\"b\"]') pasted where CSV is expected, or quoting added by docker-compose variable interpolation.","solutions":["Provide a plain comma-separated list without outer quotes: ALLOWED_HOSTS=a.com,b.com.","Remove unbalanced or stray double quotes from the value; quote only fields that truly contain commas, and keep quotes balanced.","If the value is a JSON array, convert it to CSV format or change the config field type.","Use the %q raw value in the error message to see exactly which characters broke the CSV parser."],"exampleFix":"// before\nALLOWED_HOSTS=\"a.com,b.com\"  # literal quotes reach the parser -> CSV error\n// after\nALLOWED_HOSTS=a.com,b.com","handlingStrategy":"validation","validationCode":"func assertListEnv(env string) error {\n    raw := os.Getenv(env)\n    if raw == \"\" { return nil }\n    r := csv.NewReader(strings.NewReader(strings.TrimSpace(raw)))\n    r.TrimLeadingSpace = true\n    r.LazyQuotes = true\n    if _, err := r.Read(); err != nil {\n        return fmt.Errorf(\"%s=%q is not valid CSV: %w\", env, raw, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := config.Get(&cfg); err != nil {\n    if strings.Contains(err.Error(), \"invalid CSV for\") {\n        return fmt.Errorf(\"list env vars must be CSV (a,b,c), no stray quotes: %w\", err)\n    }\n    return err\n}","preventionTips":["Write list env vars as plain comma-separated values without outer quotes","Only quote individual fields that contain commas, and keep quotes balanced","Do not paste JSON arrays into CSV-typed env vars","Preview the exact value with shell: echo \"${ALLOWED_HOSTS@Q}\" to spot added quoting"],"tags":["go","config","env","csv","parsing"],"backgroundTag":"invalid-env-value","analyzedSha":"14bfc256276775c425f988d621dccfe705de18ac","analyzedAt":"2026-09-05T12:52:36.781Z","contentChangedAt":"2026-09-05T12:52:36.781Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}