PapaParse
PapaParse copied to clipboard
Row number mismatch for different errors
Parsing a string using code below, I am seeing a mismatch in the row reported in the error messages.
Papa.parse('"heading 1","heading 2"\n"a "quoted string"","this is fine"\n"this is ok","this is good too"', { header: true, delimiter: "," });
The parsed result contains the following in the error property. I would expect the errors to contain 0 in the row field for all of the errors since the errors all occur in the first row. However, the Quotes errors contain row 1.
[
{
"type": "Quotes",
"code": "InvalidQuotes",
"message": "Trailing quote on quoted field is malformed",
"row": 1,
"index": 25
},
{
"type": "Quotes",
"code": "InvalidQuotes",
"message": "Trailing quote on quoted field is malformed",
"row": 1,
"index": 25
},
{
"type": "FieldMismatch",
"code": "TooFewFields",
"message": "Too few fields: expected 2 fields but parsed 1",
"row": 0
}
]
I'm having an odd issue where the reported row does not align with the line number the error was on, and it's resulting in duplicate errors.
I created a fiddle to prove the issue:
https://jsfiddle.net/josephdpurcell/1Lvbo93z/5/
And found that I couldn't reproduce the issue.
I looked at https://github.com/mholt/PapaParse/issues/881 and https://github.com/mholt/PapaParse/issues/432 but haven't found something exactly similar to my issue.
Given that I can't reproduce the issue and I'm not finding a similar issue in the queue I'm thinking the issue is with my logic.
I wasn't counting correctly. Here are tips when using a step function:
ParseResult.errorsis aggregate; it contains all errors- If you have
header: truethenParseResult.errors[0].rowis0for the first "row" parsed after the header, i.e. it will actually be the second row in the source file.