Skip to content

Fix CSV columnizer crash when "first line contains field names" is unchecked (#707) - #717

Merged
Hirogen merged 3 commits into
Developmentfrom
fix/707-csv-no-header
Sep 26, 2026
Merged

Hirogen merged 3 commits into
Developmentfrom
fix/707-csv-no-header

Conversation

@Hirogen

@Hirogen Hirogen commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #707

Problem

  • Unchecking "first line contains field names" in the CSV columnizer config showed an error dialog, and after that nothing was split into columns. CsvHelper's ReadHeader() throws ReaderException: Configuration.HasHeaderRecord is false., and the columnizer called it for every line, including when selecting the columnizer (Selected()).
  • Column names for files without a header were built by gluing strings together, giving Column 01, Column 11, …
  • Found while testing the fix: the columnizer instance being selected or configured is often a clone that loaded csvcolumnizer.json and never ran PreProcessLine() on the file. It kept the saved delimiter (e.g. , from an earlier comma file), not the file's own. A quoted ; file parsed with , is bad CSV data, so Selected() threw BadDataException. This happened with or without a header.

Changes (CsvColumnizer)

  • Read fields directly: a new ReadFields() helper reads each line's fields from csv.Parser.Record instead of the header API. Selected() and SplitCsvLine() both use it. Behavior for files with a header is unchanged (HeaderRecord was just Parser.Record).
  • Column names: files without a header get Column 1 … Column N.
  • Bad first line: if the first line can't be parsed with the current settings, Selected() falls back to a single Text column, as SplitCsvLine() already does. There's no exception dialog anymore.
  • Delimiter detection:
    • Selected() detects the delimiter from the file's first line, as PreProcessLine() does when a file loads.
    • Configure() detects before opening the dialog, so the dialog shows the file's delimiter.
    • After OK, the columns are rebuilt without detecting again, so a delimiter typed by the user is kept.

Tests

New tests in CSVColumnizerTest:

  • No header: Selected() gives 7 columns named Column 1–Column 7, SplitLine() returns the 7 field values, and the first line stays visible.
  • Saved , delimiter on a ; file: fields are split correctly without a header, and column names come from the header with one.
  • A first line that can't be parsed falls back to Text in both header modes.

Known limitations (not changed)

  • A delimiter typed in the dialog is replaced by the detected one when the file reloads (existing PreProcessLine() behavior).
  • Configure() still saves the detected delimiter to csvcolumnizer.json.
  • After switching header mode, the header row only reappears as data once the file reloads.

CsvHelper's ReadHeader() throws when HasHeaderRecord is false, so
Selected() failed and every line fell back to a single unsplit column.
Read fields from the parser record instead, and name generated columns
"Column 1".."Column N" (was string-concatenated to "Column 01", "Column 11").
…#707)

Selected() let CsvHelper's BadDataException escape when the first line
doesn't parse with the configured settings, e.g. a quoted ';' file read
with a ',' delimiter loaded from csvcolumnizer.json. Catch it and use the
same single-column fallback SplitCsvLine already uses.
The columnizer instance the user selects or configures is often a clone
that loaded csvcolumnizer.json and never pre-processed the file, so it
kept the saved delimiter (e.g. ',' from an earlier comma file) instead
of the file's own. Detect the delimiter from the file's first line in
Selected() and before showing the config dialog; after OK, rebuild the
columns without re-detecting so a delimiter typed by the user sticks.
@Hirogen
Hirogen merged commit d9845e2 into Development Sep 26, 2026
3 checks passed
@Hirogen
Hirogen deleted the fix/707-csv-no-header branch September 26, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSV Columnizer First Line

1 participant