windmill-labs/windmill · error
An error occurred when generating CSV:
Error message
An error occurred when generating CSV:
What it means
convertJsonToCsv wraps the json-2-csv `Parser.parse` call and rethrows any parsing failure with this prefix. It is thrown when the input array cannot be serialized to CSV — typically malformed row objects, values the parser cannot handle, or a non-array input.
Source
Thrown at frontend/src/lib/components/table/tableUtils.ts:56
})
return {
_id: nextId++,
rowData
}
})
return [hds, objs]
} else {
return [[], []]
}
}
export function convertJsonToCsv(arr: Array<Record<string, any>>): string {
try {
const parser = new Parser({})
const csv = parser.parse(arr)
return csv
} catch (err) {
throw new Error('An error occurred when generating CSV:' + err)
}
}
View on GitHub (pinned to e474e8803c)
Solutions
- Log the caught `err` (it is appended to the message) to see the exact parser complaint.
- Sanitize/flatten rows before parsing: map values to primitives or strings (JSON.stringify nested objects).
- Ensure the input is a non-empty array of plain objects with consistent keys.
- Upgrade or pin the json-2-csv dependency if the failure is a known parser bug.
Example fix
// before const csv = convertJsonToCsv(rawRows) // may throw // after const rows = rawRows.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, typeof v === 'object' ? JSON.stringify(v) : v])) ) const csv = convertJsonToCsv(rows)
Defensive patterns
Strategy: validation
Validate before calling
function isCsvSafe(rows: unknown): rows is Array<Record<string, unknown>> {
return Array.isArray(rows) && rows.length > 0 &&
rows.every((r) => r !== null && typeof r === 'object' && !Array.isArray(r))
} Type guard
function isRecordArray(v: unknown): v is Array<Record<string, any>> {
return Array.isArray(v) && v.every((x) => typeof x === 'object' && x !== null && !Array.isArray(x))
} Try / catch
try {
const csv = convertJsonToCsv(rows)
} catch (e) {
toast.error('CSV export failed: ' + (e as Error).message)
// fall back to JSON download
downloadJson(rows)
} Prevention
- Flatten/serialize nested values (JSON.stringify) before export
- Reject empty arrays and non-object rows up front
- Read the appended `err` in the message — it names the exact parser complaint
- Pin the json-2-csv version and check its changelog on upgrades
When it happens
Trigger: Calling convertJsonToCsv(arr) where `arr` contains data the json-2-csv Parser cannot serialize (nested/circular structures it chokes on, invalid delimiters via the default config, or `arr` not being an array of records).
Common situations: Exporting table data to CSV from the result grid with unusual cell values (objects, Dates in odd shapes, nulls in key positions); passing undefined/empty or heterogeneous rows from an API response.
Related errors
- CSV S3 input requires the `parquet` feature to be enabled on
- Could not generate OpenAPI document in YAML format: {}
- Could not generate OpenAPI document in JSON format: {}
- invalid json-float
- row over budget
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/db5be72516b8e641.
Report an issue: GitHub.