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

Commit 5002e00

Browse files
committed
fix(parseError): use file not path attribute
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.
1 parent 0ed7460 commit 5002e00

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

read-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,6 @@ function parseIndex (data) {
469469
function parseError (ex, file) {
470470
var e = new Error('Failed to parse json\n' + ex.message)
471471
e.code = 'EJSONPARSE'
472-
e.file = file
472+
e.path = file
473473
return e
474474
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"this is
2+
3+
Not valid json!!

test/indexjs.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ t.test('read from an index.js file', t => {
1919
})
2020
})
2121

22-
t.test('read broken json', t => {
23-
const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json')
22+
t.test('missing file', t => {
23+
// this subdirectory does not exist
24+
const fixture = resolve(__dirname, 'fixtures/indexjs-missing/package.json')
2425
read(fixture, (er, data) => {
2526
t.match(er, {
2627
code: 'ENOENT',
@@ -30,3 +31,15 @@ t.test('read broken json', t => {
3031
t.end()
3132
})
3233
})
34+
35+
t.test('EJSONPARSE', t => {
36+
const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json')
37+
read(fixture, (er, data) => {
38+
t.match(er, {
39+
code: 'EJSONPARSE',
40+
path: fixture
41+
})
42+
t.notOk(data)
43+
t.end()
44+
})
45+
})

0 commit comments

Comments
 (0)