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

BadDataException does not hold the info column mismatches #2286

Open
Manthazar opened this issue Sep 6, 2024 · 2 comments
Open

BadDataException does not hold the info column mismatches #2286

Manthazar opened this issue Sep 6, 2024 · 2 comments
Labels

Comments

@Manthazar
Copy link

Is your feature request related to a problem? Please describe.
Given there is a CSV file with quoted headers similar to:

"Business Groups", "Order Number"
"Group1",1

and colum header matching is set to:
config.PrepareHeaderForMatch = args => args.Header.ToLower(),

When we attempt to load the file we get a Bad Data Exception with no useful infomation in it:

IReader state:
   ColumnCount: 2
   CurrentIndex: -1
   HeaderRecord:

IParser state:
   ByteCount: 0
   CharCount: 35
   Row: 1
   RawRow: 1
   Count: 2
   RawRecord:
"Business Groups", "Order Number"

'

--> note the error is the space character before the quoted header starts for Order Number, CharCount 20

Describe the solution you'd like

  • The exception states that the header name xyz is unknown
  • The exception states that the format of the header is not expected
  • The char count is at the position where the format error is (it is not in 35)
  • With quoted headers, trailing or leading spaces should not lead to errors, afterall the value within the quotes is the match target

Describe alternatives you've considered

  • Comparing with files with same header policy, but working
@vivebhagat
Copy link

@Manthazar Looks like library is already handling this as configuration while reading the header.
CsvParser.ReadLine method is checking trimOptions, which is Enum with 3 values - None, Trim and InsideQuotes. The case you mentioned can be handled by assigning trimOptions to the configuration. Maybe that is what you are looking for.

@Manthazar
Copy link
Author

Thanks @vivebhagat , but this feature request is about a better error message, not the capability itself to ignore such kind of behaviour. If your upstream (application) starts to add a space for some reason, CSV helper would not be helpful to flag the reason for the parser error. Once one understood the root cause, of course then one could amend the configuration as you described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants