Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
fix(parseError): use file not path attribute
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rename file attribute to path

In order to align with the way our other "fast" json parsers work the
err.file attribute needs to be renamed to err.path.

Also other errors i.e. ENOENT attach a path attribute.
  • Loading branch information
wraithgar committed Aug 18, 2021
1 parent 0ed7460 commit 5002e00
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion read-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,6 @@ function parseIndex (data) {
function parseError (ex, file) {
var e = new Error('Failed to parse json\n' + ex.message)
e.code = 'EJSONPARSE'
e.file = file
e.path = file
return e
}
3 changes: 3 additions & 0 deletions test/fixtures/indexjs-bad/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"this is

Not valid json!!
17 changes: 15 additions & 2 deletions test/indexjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ t.test('read from an index.js file', t => {
})
})

t.test('read broken json', t => {
const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json')
t.test('missing file', t => {
// this subdirectory does not exist
const fixture = resolve(__dirname, 'fixtures/indexjs-missing/package.json')
read(fixture, (er, data) => {
t.match(er, {
code: 'ENOENT',
Expand All @@ -30,3 +31,15 @@ t.test('read broken json', t => {
t.end()
})
})

t.test('EJSONPARSE', t => {
const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json')
read(fixture, (er, data) => {
t.match(er, {
code: 'EJSONPARSE',
path: fixture
})
t.notOk(data)
t.end()
})
})

0 comments on commit 5002e00

Please sign in to comment.