-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Conversation
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' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
Note: Given the age of the PR and no response from the author for 24 hours, I have updated this PR to use |
* 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
Changed the name of the error that the parser emits from the default of
Error
toSyntaxError
. This makes it easier for users to distinguish parsing errors from other error types. This also makes the parser behave more likeJSON.parse()
, which emits aSyntaxError
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