Skip to content

Commit

Permalink
refactor(csv-parse)!: rename RECORD_INCONSISTENT_FIELDS_LENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 6, 2021
1 parent fb391c9 commit 7b55f05
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 47 deletions.
1 change: 0 additions & 1 deletion packages/csv-parse/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ We invite you to join and contribute but create an issue before engaging any wor
* errors: finish normalisation of all errors (easy)
* encoding: new encoding_input and encoding_output options (medium)
* `columns_duplicates_to_array`: this is just too long but I don't have much insipiration for a better name
* `relax_column_count`: rename INCONSISTENT_RECORD_LENGTH to RECORD_INCONSISTENT_FIELDS_LENGTH (easy)
* `info`: remove the `parser.info` object and move its properties to `state`
* `info`: rename the `info` related properties and functions to `context`
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5879,9 +5879,7 @@ class Parser extends Transform {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/dist/cjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export type CsvErrorCode =
| 'CSV_MAX_RECORD_SIZE'
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
| 'CSV_QUOTE_NOT_CLOSED'
| 'CSV_INCONSISTENT_RECORD_LENGTH'
| 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
| 'CSV_OPTION_COLUMNS_MISSING_NAME'

Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/cjs/sync.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5879,9 +5879,7 @@ class Parser extends Transform {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/dist/esm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export type CsvErrorCode =
| 'CSV_MAX_RECORD_SIZE'
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
| 'CSV_QUOTE_NOT_CLOSED'
| 'CSV_INCONSISTENT_RECORD_LENGTH'
| 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
| 'CSV_OPTION_COLUMNS_MISSING_NAME'

Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5875,9 +5875,7 @@ class Parser extends Transform {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/esm/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5875,9 +5875,7 @@ class Parser extends Transform {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/iife/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5878,9 +5878,7 @@ var csv_parse = (function (exports) {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/iife/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5878,9 +5878,7 @@ var csv_parse_sync = (function (exports) {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5881,9 +5881,7 @@
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/umd/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5881,9 +5881,7 @@
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export type CsvErrorCode =
| 'CSV_MAX_RECORD_SIZE'
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
| 'CSV_QUOTE_NOT_CLOSED'
| 'CSV_INCONSISTENT_RECORD_LENGTH'
| 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
| 'CSV_OPTION_COLUMNS_MISSING_NAME'

Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,7 @@ class Parser extends Transform {
}
if(recordLength !== this.state.expectedRecordLength){
const err = columns === false ?
// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to
// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH
new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', [
'Invalid Record Length:',
`expect ${this.state.expectedRecordLength},`,
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const records = parse('1,2\nin:va:lid\n3,4', {
relax_column_count: true,
raw: true,
on_record: ({raw, record}, {error}) => {
if(error && error.code === 'CSV_INCONSISTENT_RECORD_LENGTH'){
if(error && error.code === 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'){
return raw.trim().split(':');
} else {
return record;
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/test/api.types.sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('API Types', () => {
})

it('CsvErrorCode', () => {
const err = new CsvError('CSV_INCONSISTENT_RECORD_LENGTH', 'error');
const err = new CsvError('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH', 'error');
const code: CsvErrorCode = err.code;
return code;
})
Expand Down
14 changes: 7 additions & 7 deletions packages/csv-parse/test/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,23 +340,23 @@ describe('API Types', () => {
describe('CsvError', () => {
describe('Typescript definition is accurate', () => {
it('Minimum', () => {
const error = new CsvError("CSV_INCONSISTENT_RECORD_LENGTH", "MESSAGE");
const error = new CsvError("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH", "MESSAGE");

error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH")
error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH")
error.message.should.eql("MESSAGE")
})

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

error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH")
error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH")
error.message.should.eql("MESSAGE1 MESSAGE2")
})

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

error.code.should.eql("CSV_INCONSISTENT_RECORD_LENGTH")
error.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH")
error.message.should.eql("MESSAGE")
error.should.have.key("testContext").and.eql({ testProp: "testValue" })
})
Expand All @@ -366,7 +366,7 @@ describe('API Types', () => {
parse(`a,b\nc`, function (e: Error|undefined) {
const isCsvError = e instanceof CsvError;
isCsvError.should.be.true();
(e as CsvError).code.should.eql('CSV_INCONSISTENT_RECORD_LENGTH');
(e as CsvError).code.should.eql('CSV_RECORD_INCONSISTENT_FIELDS_LENGTH');
})
})
})
Expand Down
10 changes: 5 additions & 5 deletions packages/csv-parse/test/option.relax_column_count.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe 'Option `relax_column_count`', ->
4,5
""", (err) ->
assert_error err,
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
message: 'Invalid Record Length: expect 3, got 2 on line 2'
record: ['4', '5']
next()
Expand All @@ -36,7 +36,7 @@ describe 'Option `relax_column_count`', ->
"""
, (err) ->
assert_error err,
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
message: 'Invalid Record Length: expect 2, got 1 on line 2'
record: ['1']
next()
Expand Down Expand Up @@ -106,7 +106,7 @@ describe 'Option `relax_column_count`', ->
a,b
""", relax_column_count_more: true, (err) ->
assert_error err,
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
message: 'Invalid Record Length: expect 3, got 2 on line 2'
record: ['a', 'b']
next()
Expand All @@ -130,7 +130,7 @@ describe 'Option `relax_column_count`', ->
a,b,c,d
""", relax_column_count_less: true, (err) ->
assert_error err,
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
message: 'Invalid Record Length: expect 3, got 4 on line 2'
record: ['a', 'b', 'c', 'd']
next()
Expand All @@ -146,7 +146,7 @@ describe 'Option `relax_column_count`', ->
relax_column_count: true,
raw: true,
on_record: ({raw, record}, {error}) ->
if error?.code is 'CSV_INCONSISTENT_RECORD_LENGTH'
if error?.code is 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
raw.trim().split ':'
else
record
Expand Down
4 changes: 2 additions & 2 deletions packages/csv-parse/test/option.skip_records_with_error.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe 'Option `skip_records_with_error`', ->
parser.end()


it 'handle "CSV_INCONSISTENT_RECORD_LENGTH"', (next) ->
it 'handle "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH"', (next) ->
errors = 0
parser = parse skip_records_with_error: true, (err, records) ->
records.should.eql [
Expand All @@ -120,7 +120,7 @@ describe 'Option `skip_records_with_error`', ->
parser.on 'skip', (err) ->
assert_error err,
message: 'Invalid Record Length: expect 4, got 3 on line 2'
code: 'CSV_INCONSISTENT_RECORD_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH'
record: ['1', '2', '3']
errors++
parser.write '''
Expand Down

0 comments on commit 7b55f05

Please sign in to comment.