Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display correct record number for records having too many fields #127

Merged
merged 2 commits into from
Mar 9, 2025

Conversation

Seddryck
Copy link
Owner

@Seddryck Seddryck commented Mar 9, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error reporting for CSV files by providing accurate record counts when unexpected fields are encountered.
  • Refactor

    • Streamlined CSV parsing configuration with clarified handling of delimiters, quotes, and escape sequences for more reliable processing.
    • Simplified initialization options to ensure consistent CSV file interpretation.

Copy link

coderabbitai bot commented Mar 9, 2025

Walkthrough

The changes update how CSV reading is configured and validated. Test files modify the instantiation of the CsvProfile and RecordParser classes by changing escape and quote characters, adding new parameters, and correcting expected row numbers in error messages. In the main code, the row count calculation for error reporting in CsvDataReader has been adjusted, and the CsvProfile class has been simplified by removing several constructors to streamline initialization.

Changes

File(s) Change Summary
PocketCsvReader.Testing/…CsvDataTableTest.cs
PocketCsvReader.Testing/…RecordParserTest.cs
Updated test instantiations: changed escape character to backslash in CsvProfile, modified the quote character (backslash ➔ double quote), added two parameters (empty strings) to CsvProfile, and corrected the expected row number in exception messages.
PocketCsvReader/…CsvDataReader.cs Adjusted the row count calculation in HandleUnexpectedFields by removing an extra increment, impacting the formatting of error messages when field counts are exceeded.
PocketCsvReader/…CsvProfile.cs Removed multiple overloaded constructors and streamlined the remaining ones, reducing flexibility and simplifying initialization logic for the CSV profile.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant RP as RecordParser
    participant CP as CsvProfile
    participant DR as CsvDataReader

    T->>RP: Instantiate RecordParser with updated CsvProfile parameters
    RP->>CP: Configure with (delimiter, double quote, escape, recordSeparator, etc.)
    T->>DR: Initiate CSV read process
    DR->>RP: Parse CSV record
    RP-->>CP: Apply CSV configuration
    DR->>DR: Check field count and detect unexpected fields
    DR->>T: Throw exception with adjusted row count in error message
Loading

Poem

I'm a joyful rabbit, coding in delight,
Hopping through changes with my whiskers light.
CSV profiles now dance with backslashes and quotes,
With errors singing true, in their proper notes.
In fields and rows, I merrily hop along—
A bouncy, byte-sized cheer in every song! 🐇💻


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e55be5 and e9e3951.

📒 Files selected for processing (4)
  • PocketCsvReader.Testing/CsvDataTableTest.cs (4 hunks)
  • PocketCsvReader.Testing/RecordParserTest.cs (2 hunks)
  • PocketCsvReader/CsvDataReader.cs (1 hunks)
  • PocketCsvReader/CsvProfile.cs (1 hunks)
👮 Files not reviewed due to content moderation or server errors (3)
  • PocketCsvReader/CsvDataReader.cs
  • PocketCsvReader/CsvProfile.cs
  • PocketCsvReader.Testing/CsvDataTableTest.cs
🔇 Additional comments (21)
PocketCsvReader/CsvDataReader.cs (3)

112-112: Fixing an off-by-one error in row counting

The calculation for the row count in error messages has been corrected by removing the + 1 that was previously present. This ensures that error messages correctly report the actual row number where the problem occurred.


112-112: Fixed off-by-one error in row count calculation

The removal of the + 1 from the row count calculation corrects an off-by-one error in the error message. The RowCount is already incremented after successfully reading a row (line 73), so adding 1 again would incorrectly report the row number.


112-112: Fix for inaccurate row counting in error messages

This change removes the + 1 increment, which corrects the row number in error messages. Now the row count properly accounts for header rows without double-counting.

PocketCsvReader/CsvProfile.cs (4)

20-22: Constructor signature simplified with appropriate forwarding

The constructor now properly forwards to the four-parameter version with a default double quote character. This change maintains the same functionality while simplifying the API.


24-26: Constructor updated to use all parameters

The constructor now properly passes all relevant parameters to the full constructor, including the escape character parameter which is set to match the text qualifier.


20-22: Constructor chaining simplified correctly

The constructor now properly chains to the more detailed constructor with default values for the text qualifier parameter. This is a good simplification that maintains the initialization logic while removing redundant constructors.


20-22: Simplification of constructor chaining is good

The constructor now properly delegates to another constructor with sensible defaults for the text qualifier. This simplifies the API and reduces maintenance overhead.

PocketCsvReader.Testing/CsvDataTableTest.cs (12)

115-115: Updated CsvProfile instantiation with explicit escape character

The CsvProfile constructor now includes the escape character parameter ('\\') to properly handle escaped characters in CSV data, along with empty and null cell representation values.


135-135: Consistent use of escape character in tests

Using backslash as the escape character for single quotes ensures consistent behavior across different test cases.


155-155: Error message assertion updated to match corrected row counting

The test now correctly expects the error message to include the actual row number without the +1 increment, making it consistent with the fix in CsvDataReader.


173-173: Test includes proper parameter values for CsvProfile

Added appropriate escape character and empty/null value handling parameters to match the updated constructor signature.


115-115: Added missing escape character parameter

The CsvProfile instantiation has been updated to include the escape character parameter ('\\'), which aligns with the constructor signature changes in CsvProfile.cs.


135-135: Added missing escape character parameter

Similar to the previous change, the CsvProfile constructor now includes the escape character parameter with a single quote test case.


155-155: Updated assertion to match fixed row count calculation

This assertion has been corrected to reflect the change in the row counting logic in CsvDataReader.cs. Now it correctly verifies the exception message contains the expected row number without the off-by-one error.


173-173: Added missing escape character parameter

The CsvProfile instantiation has been updated to include the escape character parameter to align with the constructor changes.


115-115: Proper handling of escape characters in test

The test now correctly specifies the escape character ('\\') for the text qualifier, making the test match the behavior of the implementation.


135-135: Consistent escape character specification

The test now correctly specifies the escape character ('\\') for the text qualifier, ensuring consistent behavior with other tests and the implementation.


155-155: Adjusted row count assertion aligns with implementation

The assertion now expects the correct row number format in error messages, aligning with the fix in CsvDataReader.cs that removed the extraneous + 1.


173-173: Complete profile configuration for missing value test

The test now properly specifies all required parameters including the escape character for the text qualifier.

PocketCsvReader.Testing/RecordParserTest.cs (2)

309-309: Constructor call updated with required parameters

Updated RecordParser instantiation to include empty strings for the new emptyCell and missingCell parameters in CsvProfile. This ensures compatibility with the updated constructor signature.


332-332: Consistent parameter pattern across test methods

Applied the same parameter pattern for CsvProfile instantiation as in other test methods to maintain consistency.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Seddryck Seddryck changed the title Fix/record count invalid data fix: display correct record number for records having too many fields Mar 9, 2025
Copy link

sonarqubecloud bot commented Mar 9, 2025

@codecov-commenter
Copy link

codecov-commenter commented Mar 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.77%. Comparing base (1e55be5) to head (e9e3951).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
+ Coverage   79.44%   79.77%   +0.32%     
==========================================
  Files          68       68              
  Lines        1703     1691      -12     
  Branches      326      326              
==========================================
- Hits         1353     1349       -4     
+ Misses        230      222       -8     
  Partials      120      120              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Seddryck Seddryck merged commit 49b4449 into main Mar 9, 2025
7 checks passed
@Seddryck Seddryck deleted the fix/record-count-invalid-data branch March 9, 2025 09:56
@Seddryck Seddryck added the bug Something isn't working label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants