Skip to content

libfec fastfec panics on filings with [BEGINTEXT]/[ENDTEXT] records #11

Description

@asg017

Note

Much of this ticket was composed with Claude

Description

When processing large filings that contain [BEGINTEXT]/[ENDTEXT] blocks (used for F99 miscellaneous text and TEXT records), libfec fastfec panics with:

thread 'main' panicked at crates/fec-cli/src/commands/fastfec.rs:89:18:
CSV position to be available

The [BEGINTEXT]/[ENDTEXT] handler in Filing::next_row() constructs a new StringRecord from the text content, but this record lacks the CSV byte-position metadata. The progress bar code then calls .expect() on the missing position.

Root Cause

fastfec.rs:86-90:

pb.set_position(
    r.record
        .position()
        .expect("CSV position to be available")
        .byte(),
);

Records emitted from [BEGINTEXT]/[ENDTEXT] processing (in lib.rs:344-382) are constructed from the next record after [ENDTEXT], which may not have position info depending on the CSV reader state.

Affected Filing

Filing ID: 1947601 (130MB, Trump for President F3PA filing FEC-1434701)

Reproduction

# libfec panics:
libfec fastfec ~/.cache/libfec/cache/1947601.fec /tmp/out_libfec
# thread 'main' panicked at crates/fec-cli/src/commands/fastfec.rs:89:18:
# CSV position to be available

# FastFEC succeeds:
fastfec --no-stdin ~/.cache/libfec/cache/1947601.fec /tmp/out_fastfec
# Done; parsing successful!

Observe the Difference

# libfec produces no output (panics before completing):
ls /tmp/out_libfec/1947601/ 2>/dev/null || echo "directory incomplete or missing"

# FastFEC produces full output:
ls /tmp/out_fastfec/1947601/
# F3PA.csv  SA20A.csv  SB23.csv  SB29.csv  SD12.csv  TEXT.csv  header.csv

Suggested Fix

Replace .expect("CSV position to be available") with a fallback:

if let Some(pos) = r.record.position() {
    pb.set_position(pos.byte());
}

(NOTE: wait no, we can copy the position data from the original StringRecord to the new one, right?)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions