PapaParse icon indicating copy to clipboard operation
PapaParse copied to clipboard

Row number mismatch for different errors

Open dereksdev opened this issue 3 years ago • 2 comments
trafficstars

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
  }
]

dereksdev avatar Apr 12 '22 20:04 dereksdev

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.

josephdpurcell avatar Apr 10 '23 14:04 josephdpurcell

I wasn't counting correctly. Here are tips when using a step function:

  1. ParseResult.errors is aggregate; it contains all errors
  2. If you have header: true then ParseResult.errors[0].row is 0 for the first "row" parsed after the header, i.e. it will actually be the second row in the source file.

josephdpurcell avatar Apr 10 '23 17:04 josephdpurcell