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

Set error name to SyntaxError #73

Merged
merged 5 commits into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ Parser.prototype._online = function (buf, start, end) {
}

if (this.strict && cells.length !== this.headers.length) {
this.emit('error', new Error('Row length does not match headers'))
const e = new RangeError('Row length does not match headers')
this.emit('error', e)
} else {
this._emit(this._Row, cells)
}
Expand Down
4 changes: 3 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const test = require('tape')
const fs = require('fs')
const path = require('path')
const eol = require('os').EOL
const bops = require('bops')
const spectrum = require('csv-spectrum')
const concat = require('concat-stream')
const csv = require('..')

const read = fs.createReadStream
const eol = '\n'

test('simple csv', (t) => {
collect('dummy.csv', verify)
Expand Down Expand Up @@ -236,6 +237,7 @@ test('custom newline', (t) => {
test('optional strict', (t) => {
collect('test_strict.csv', { strict: true }, verify)
function verify (err, lines) {
t.equal(err.name, 'RangeError', 'err name')
t.equal(err.message, 'Row length does not match headers', 'strict row length')
t.same(lines[0], { a: '1', b: '2', c: '3' }, 'first row')
t.same(lines[1], { a: '4', b: '5', c: '6' }, 'second row')
Expand Down