{"record":{"id":"130b83d73f8a12c1","repo":"nextlevelbuilder/ui-ux-pro-max-skill","slug":"unterminated-quoted-csv-field","errorCode":null,"errorMessage":"Unterminated quoted CSV field","messagePattern":"Unterminated quoted CSV field","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gallery/lib/parseStyles.ts","lineNumber":61,"sourceCode":"  for (let i = 0; i < content.length; i++) {\n    const char = content[i];\n    if (char === '\"') {\n      current += char;\n      if (inQuotes && content[i + 1] === '\"') {\n        current += content[++i];\n      } else {\n        inQuotes = !inQuotes;\n      }\n    } else if (!inQuotes && (char === \"\\n\" || char === \"\\r\")) {\n      if (current.trim()) records.push(current);\n      current = \"\";\n      if (char === \"\\r\" && content[i + 1] === \"\\n\") i++;\n    } else {\n      current += char;\n    }\n  }\n  if (current.trim()) records.push(current);\n  if (inQuotes) throw new Error(\"Unterminated quoted CSV field\");\n  return records;\n}\n\nexport function parseStylesCSV(csvContent: string): StyleData[] {\n  const lines = splitCSVRecords(csvContent);\n  if (lines.length < 2) return [];\n\n  const headers = parseCSVLine(lines[0]);\n  const column = new Map(headers.map((header, index) => [header, index]));\n  const value = (fields: string[], header: string): string => {\n    const index = column.get(header);\n    return index === undefined ? \"\" : fields[index] || \"\";\n  };\n\n  const dataLines = lines.slice(1);\n  return dataLines.map((line) => {\n    const f = parseCSVLine(line);\n    const primaryColors = value(f, \"Primary Colors\");","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/nextlevelbuilder/ui-ux-pro-max-skill/blob/a38d04c3d5c298c851dbe5e6ee1965ee3de42cb5/gallery/lib/parseStyles.ts#L43-L79","documentation":"The gallery CSV parser (splitCSVRecords) walks the styles.csv content character by character tracking quote state; if it reaches end-of-input while still inside a quoted field (inQuotes is true), the record can never be terminated and it throws. This means the CSV is truncated or has an odd number of quote characters — a malformed source file, not bad query data.","triggerScenarios":"Feeding parseStylesCSV() a styles.csv where a quoted multi-line field (descriptions with embedded newlines) lost its closing quote, a file truncated mid-field by a partial git checkout or bad copy, or programmatic CSV generation that doesn't escape/double inner quotes correctly.","commonSituations":"Hand-editing styles.csv and deleting a closing quote; CSV writers that emit raw quotes inside fields without doubling them; files edited with tools that strip or smarten quotes; line-ending rewrites breaking the parser's CRLF handling.","solutions":["Open the gallery's styles.csv, go to the last record the parser reached, and fix the unbalanced quote — remember quoted fields may span multiple lines.","Ensure every quote character inside a quoted field is doubled (escaped as two quotes).","Regenerate the CSV from the source of truth (src/ui-ux-pro-max/data/styles.csv via `npm run sync:assets`) instead of editing the gallery copy.","If generating programmatically, use a proper CSV writer library rather than string concatenation."],"exampleFix":"# before (broken csv - closing quote lost, inner quote not doubled)\n5,\"Neubrutalism,bold \"outlines\" ...\n# after (inner quotes doubled, field terminated)\n5,\"Neubrutalism,bold \"\"outlines\"\" ...\"","handlingStrategy":"validation","validationCode":"function csvQuotesBalanced(content: string): boolean {\n  let inQuotes = false;\n  for (let i = 0; i < content.length; i++) {\n    if (content[i] === '\"') {\n      if (inQuotes && content[i + 1] === '\"') i++; // escaped quote\n      else inQuotes = !inQuotes;\n    }\n  }\n  return !inQuotes;\n}\n\nif (!csvQuotesBalanced(stylesCsv)) {\n  throw new Error('styles.csv has an unterminated quoted field - fix the source CSV');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const styles = parseStylesCSV(csv);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Unterminated quoted CSV field')) {\n    console.error('Malformed styles.csv - likely a lost closing quote; validate with a CSV linter');\n  }\n  throw e;\n}","preventionTips":["Lint CSVs in CI (balanced quotes, header contract) before the gallery build.","Generate CSVs with a real writer library that escapes inner quotes by doubling them.","Never hand-edit the generated copy; edit the source of truth and re-run sync:assets."],"tags":["csv","parsing","gallery","validation"],"backgroundTag":null,"analyzedSha":"a38d04c3d5c298c851dbe5e6ee1965ee3de42cb5","analyzedAt":"2026-08-14T18:51:02.321Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}