Skip to content

Commit 7b55f05

Browse files
committed
refactor(csv-parse)!: rename RECORD_INCONSISTENT_FIELDS_LENGTH
1 parent fb391c9 commit 7b55f05

18 files changed

+28
-47
lines changed

packages/csv-parse/ROADMAP.md

-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ We invite you to join and contribute but create an issue before engaging any wor
99
* errors: finish normalisation of all errors (easy)
1010
* encoding: new encoding_input and encoding_output options (medium)
1111
* `columns_duplicates_to_array`: this is just too long but I don't have much insipiration for a better name
12-
* `relax_column_count`: rename INCONSISTENT_RECORD_LENGTH to RECORD_INCONSISTENT_FIELDS_LENGTH (easy)
1312
* `info`: remove the `parser.info` object and move its properties to `state`
1413
* `info`: rename the `info` related properties and functions to `context`

packages/csv-parse/dist/cjs/index.cjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5879,9 +5879,7 @@ class Parser extends Transform {
58795879
}
58805880
if(recordLength !== this.state.expectedRecordLength){
58815881
const err = columns === false ?
5882-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5883-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5884-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5882+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58855883
'Invalid Record Length:',
58865884
`expect ${this.state.expectedRecordLength},`,
58875885
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/cjs/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export type CsvErrorCode =
253253
| 'CSV_MAX_RECORD_SIZE'
254254
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
255255
| 'CSV_QUOTE_NOT_CLOSED'
256-
| 'CSV_INCONSISTENT_RECORD_LENGTH'
256+
| 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
257257
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
258258
| 'CSV_OPTION_COLUMNS_MISSING_NAME'
259259

packages/csv-parse/dist/cjs/sync.cjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5879,9 +5879,7 @@ class Parser extends Transform {
58795879
}
58805880
if(recordLength !== this.state.expectedRecordLength){
58815881
const err = columns === false ?
5882-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5883-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5884-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5882+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58855883
'Invalid Record Length:',
58865884
`expect ${this.state.expectedRecordLength},`,
58875885
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/esm/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export type CsvErrorCode =
253253
| 'CSV_MAX_RECORD_SIZE'
254254
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
255255
| 'CSV_QUOTE_NOT_CLOSED'
256-
| 'CSV_INCONSISTENT_RECORD_LENGTH'
256+
| 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
257257
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
258258
| 'CSV_OPTION_COLUMNS_MISSING_NAME'
259259

packages/csv-parse/dist/esm/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5875,9 +5875,7 @@ class Parser extends Transform {
58755875
}
58765876
if(recordLength !== this.state.expectedRecordLength){
58775877
const err = columns === false ?
5878-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5879-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5880-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5878+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58815879
'Invalid Record Length:',
58825880
`expect ${this.state.expectedRecordLength},`,
58835881
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/esm/sync.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5875,9 +5875,7 @@ class Parser extends Transform {
58755875
}
58765876
if(recordLength !== this.state.expectedRecordLength){
58775877
const err = columns === false ?
5878-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5879-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5880-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5878+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58815879
'Invalid Record Length:',
58825880
`expect ${this.state.expectedRecordLength},`,
58835881
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/iife/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5878,9 +5878,7 @@ var csv_parse = (function (exports) {
58785878
}
58795879
if(recordLength !== this.state.expectedRecordLength){
58805880
const err = columns === false ?
5881-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5882-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5883-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5881+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58845882
'Invalid Record Length:',
58855883
`expect ${this.state.expectedRecordLength},`,
58865884
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/iife/sync.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5878,9 +5878,7 @@ var csv_parse_sync = (function (exports) {
58785878
}
58795879
if(recordLength !== this.state.expectedRecordLength){
58805880
const err = columns === false ?
5881-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5882-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5883-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5881+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58845882
'Invalid Record Length:',
58855883
`expect ${this.state.expectedRecordLength},`,
58865884
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/umd/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5881,9 +5881,7 @@
58815881
}
58825882
if(recordLength !== this.state.expectedRecordLength){
58835883
const err = columns === false ?
5884-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5885-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5886-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5884+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58875885
'Invalid Record Length:',
58885886
`expect ${this.state.expectedRecordLength},`,
58895887
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/dist/umd/sync.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5881,9 +5881,7 @@
58815881
}
58825882
if(recordLength !== this.state.expectedRecordLength){
58835883
const err = columns === false ?
5884-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
5885-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
5886-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
5884+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
58875885
'Invalid Record Length:',
58885886
`expect ${this.state.expectedRecordLength},`,
58895887
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/lib/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export type CsvErrorCode =
253253
| 'CSV_MAX_RECORD_SIZE'
254254
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
255255
| 'CSV_QUOTE_NOT_CLOSED'
256-
| 'CSV_INCONSISTENT_RECORD_LENGTH'
256+
| 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
257257
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
258258
| 'CSV_OPTION_COLUMNS_MISSING_NAME'
259259

packages/csv-parse/lib/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,7 @@ class Parser extends Transform {
879879
}
880880
if(recordLength !== this.state.expectedRecordLength){
881881
const err = columns === false ?
882-
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
883-
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
884-
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
882+
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
885883
'Invalid Record Length:',
886884
`expect ${this.state.expectedRecordLength},`,
887885
`got ${recordLength} on line ${this.info.lines}`,

packages/csv-parse/samples/option.relax_column_count.record_inconsistent_length.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const records = parse('1,2\nin:va:lid\n3,4', {
66
relax_column_count: true,
77
raw: true,
88
on_record: ({raw, record}, {error}) => {
9-
if(error && error.code === 'CSV_INCONSISTENT_RECORD_LENGTH'){
9+
if(error && error.code === 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'){
1010
return raw.trim().split(':');
1111
} else {
1212
return record;

packages/csv-parse/test/api.types.sync.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('API Types', () => {
7272
})
7373

7474
it('CsvErrorCode', () => {
75-
const err = new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', 'error');
75+
const err = new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', 'error');
7676
const code: CsvErrorCode = err.code;
7777
return code;
7878
})

packages/csv-parse/test/api.types.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -340,23 +340,23 @@ describe('API Types', () => {
340340
describe('CsvError', () => {
341341
describe('Typescript definition is accurate', () => {
342342
it('Minimum', () => {
343-
const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", "MESSAGE");
343+
const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", "MESSAGE");
344344

345-
error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH")
345+
error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH")
346346
error.message.should.eql("MESSAGE")
347347
})
348348

349349
it('Multiple messages', () => {
350-
const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", ["MESSAGE1", "MESSAGE2"])
350+
const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", ["MESSAGE1", "MESSAGE2"])
351351

352-
error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH")
352+
error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH")
353353
error.message.should.eql("MESSAGE1 MESSAGE2")
354354
})
355355

356356
it('Supports contexts', () => {
357-
const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", "MESSAGE", {}, { testContext: { testProp: "testValue" } })
357+
const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", "MESSAGE", {}, { testContext: { testProp: "testValue" } })
358358

359-
error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH")
359+
error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH")
360360
error.message.should.eql("MESSAGE")
361361
error.should.have.key("testContext").and.eql({ testProp: "testValue" })
362362
})
@@ -366,7 +366,7 @@ describe('API Types', () => {
366366
parse(`a,b\nc`, function (e: Error|undefined) {
367367
const isCsvError = e instanceof CsvError;
368368
isCsvError.should.be.true();
369-
(e as CsvError).code.should.eql('CSV_INCONSISTENT_RECORD_LENGTH');
369+
(e as CsvError).code.should.eql('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH');
370370
})
371371
})
372372
})

packages/csv-parse/test/option.relax_column_count.coffee

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe 'Option `relax_column_count`', ->
2222
4,5
2323
""", (err) ->
2424
assert_error err,
25-
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
25+
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
2626
message: 'Invalid Record Length: expect 3, got 2 on line 2'
2727
record: ['4', '5']
2828
next()
@@ -36,7 +36,7 @@ describe 'Option `relax_column_count`', ->
3636
"""
3737
, (err) ->
3838
assert_error err,
39-
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
39+
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
4040
message: 'Invalid Record Length: expect 2, got 1 on line 2'
4141
record: ['1']
4242
next()
@@ -106,7 +106,7 @@ describe 'Option `relax_column_count`', ->
106106
a,b
107107
""", relax_column_count_more: true, (err) ->
108108
assert_error err,
109-
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
109+
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
110110
message: 'Invalid Record Length: expect 3, got 2 on line 2'
111111
record: ['a', 'b']
112112
next()
@@ -130,7 +130,7 @@ describe 'Option `relax_column_count`', ->
130130
a,b,c,d
131131
""", relax_column_count_less: true, (err) ->
132132
assert_error err,
133-
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
133+
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
134134
message: 'Invalid Record Length: expect 3, got 4 on line 2'
135135
record: ['a', 'b', 'c', 'd']
136136
next()
@@ -146,7 +146,7 @@ describe 'Option `relax_column_count`', ->
146146
relax_column_count: true,
147147
raw: true,
148148
on_record: ({raw, record}, {error}) ->
149-
if error?.code is 'CSV_INCONSISTENT_RECORD_LENGTH'
149+
if error?.code is 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
150150
raw.trim().split ':'
151151
else
152152
record

packages/csv-parse/test/option.skip_records_with_error.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe 'Option `skip_records_with_error`', ->
108108
parser.end()
109109

110110

111-
it 'handle "CSV_INCONSISTENT_RECORD_LENGTH"', (next) ->
111+
it 'handle "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH"', (next) ->
112112
errors = 0
113113
parser = parse skip_records_with_error: true, (err, records) ->
114114
records.should.eql [
@@ -120,7 +120,7 @@ describe 'Option `skip_records_with_error`', ->
120120
parser.on 'skip', (err) ->
121121
assert_error err,
122122
message: 'Invalid Record Length: expect 4, got 3 on line 2'
123-
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
123+
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
124124
record: ['1', '2', '3']
125125
errors++
126126
parser.write '''

0 commit comments

Comments
 (0)