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

Conversation

jkehres
Copy link

@jkehres jkehres commented Jun 22, 2017

Changed the name of the error that the parser emits from the default of Error to SyntaxError. This makes it easier for users to distinguish parsing errors from other error types. This also makes the parser behave more like JSON.parse(), which emits a SyntaxError when it encounters invalid JSON.

See the following for details on Error.name:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name

test/test.js Outdated
var bops = require('bops')
var spectrum = require('csv-spectrum')
var concat = require('concat-stream')
var csv = require('..')
var read = fs.createReadStream
var eol = '\n'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows EOL is '\r\n', which causes a few tests to fail. Making this '\n' across all operating systems fixes this problem.

index.js Outdated
@@ -156,7 +156,9 @@ 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'))
var e = new Error('Row length does not match headers')
e.name = 'SyntaxError'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that SyntaxError is correct here. According to the Node docs: https://nodejs.org/api/errors.html#errors_class_syntaxerror, this is used only for invalid JavaScript , or as a result of code evaluation.

RangeError should be more appropriate https://nodejs.org/api/errors.html#errors_class_rangeerror. And it's a built-in, so no need to set the name property, just instantiate directly.

@shellscape shellscape changed the base branch from master to v2.0 August 18, 2018 15:13
@shellscape
Copy link
Collaborator

Note: Given the age of the PR and no response from the author for 24 hours, I have updated this PR to use RangeError as suggested. And have changed this PR's target to the v2.0 branch, as modifying an Error type can be considered a breaking change.

@shellscape shellscape mentioned this pull request Aug 18, 2018
@shellscape shellscape merged commit df66306 into mafintosh:v2.0 Aug 18, 2018
@shellscape shellscape mentioned this pull request Aug 22, 2018
shellscape added a commit that referenced this pull request Sep 25, 2018
* chore: add metadata, update package, use eslint+standard

* chore: update pre-commit hook

* refactor: update linting for node 6+

* chore: make bench a script

* refactor: make benchmarks a bin, add style

* fix: index linting without breaking tests

* fix: bench bin should accept file input

* docs: spruce up the README

* chore: reorg binaries

* chore: add repo labels json

* refactor: Use RangeError (#73)

* Set error name to SyntaxError

* chore: use RangeError

* test: use RangeError

* chore: var -> const

* docs: add --remove to readme

* chore: update bug template

* chore: update mod template

* test: migrate to ava, snapshots

* refactor: ES6 all the things

* feat: add skipLines option (#64)

* skips setting header row unti a specified string is found in the cells

* only emit(this._Row, cells) if it's not the first row

* update README to show skipUntil option

* update README to show skipUntil option

* update README.md [remove extra comma]

* fix tests

* skipUntil skips setting headers until line number is reached

* update readme to show that skipUntil takes a line number int

* remove extra blank line

* change name of skipUntil opt to skipLines

* add cli flags for skipLines

* remove extra blank line in junk_rows.csv

* update README.md with CLI flag for skipLines

* chore: alphabetize option in README

* chore: alphabetize CLI flag

* chore: update flag description in CLI

* zero indexed skipLines

* update test to ava

* fix test errors

* chore: alphabetize, use string literals

* feat: allow headers: false, index column names

* chore: remove tape dependency

* docs: add headers:false output example

* chore(release): 2.0.0-beta.0

* chore: better benchmark profiling

* docs: add benchmarks

* chore: add files to package.json to reduce tarball size

* feat: provide header, index to mapValues and mapHeaders

* chore(release): 2.0.0-beta.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants