Skip to content

Fix CSV row column mismatch error during migration#160

Open
claudear wants to merge 1 commit intomainfrom
fix/csv-row-column-mismatch
Open

Fix CSV row column mismatch error during migration#160
claudear wants to merge 1 commit intomainfrom
fix/csv-row-column-mismatch

Conversation

@claudear
Copy link

Summary

  • Fixes Sentry issue CLOUD-3EFG: "CSV row does not match the number of header columns" (35 events)
  • Instead of throwing an exception that crashes the entire migration, the CSV source now gracefully handles common CSV inconsistencies:
    • Trailing blank lines: fgetcsv returns [''] for these — now skipped
    • Short rows (fewer columns than headers): padded with empty strings
    • Extra columns: truncated to match header count

Test plan

  • Added testCSVParsingHandlesTrailingEmptyLines — verifies trailing blank lines are skipped
  • Added testCSVParsingHandlesShortRows — verifies short rows are padded correctly
  • All existing CSV tests pass (9/9)
  • All unit tests pass (17/17)
  • Code style (pint) passes

🤖 Generated with Claude Code

Instead of throwing "CSV row does not match the number of header columns"
which crashes the entire migration, handle common CSV inconsistencies:
- Skip empty/trailing blank rows (fgetcsv returns [''] for these)
- Pad short rows with empty strings for missing trailing columns
- Truncate rows with extra columns to match header count

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

Warning

Rate limit exceeded

@claudear has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 817de860-4582-4aa1-8ea7-fe1b63bcccbb

📥 Commits

Reviewing files that changed from the base of the PR and between bbdd8ef and 23fa267.

⛔ Files ignored due to path filters (2)
  • tests/Migration/resources/csv/short_rows.csv is excluded by !**/*.csv
  • tests/Migration/resources/csv/trailing_empty_lines.csv is excluded by !**/*.csv
📒 Files selected for processing (2)
  • src/Migration/Sources/CSV.php
  • tests/Migration/Unit/General/CSVTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/csv-row-column-mismatch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claudear
Copy link
Author

Fix Confidence: 90/100

The fix addresses the exact error from Sentry by handling three common CSV inconsistencies that cause column count mismatches: trailing blank lines (most likely cause of the 35 events), short rows, and extra columns. The fix is minimal and defensive - it doesn't change the happy path behavior, only handles edge cases that previously threw. All existing tests pass and new tests cover the fix.

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.

1 participant