Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 08f60c3

Browse files
committed
fix: make error messages consistent with go for interop tests
License: MIT Signed-off-by: achingbrain <[email protected]>
1 parent a69ba91 commit 08f60c3

File tree

15 files changed

+51
-29
lines changed

15 files changed

+51
-29
lines changed

src/core/utils/errors.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
class NonFatalError extends Error {
4+
constructor (message) {
5+
super(message)
6+
7+
this.code = 0
8+
}
9+
}
10+
11+
class FatalError extends Error {
12+
constructor (message) {
13+
super(message)
14+
15+
this.code = 1
16+
}
17+
}
18+
19+
module.exports = {
20+
NonFatalError,
21+
FatalError
22+
}

src/core/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
countStreamBytes: require('./count-stream-bytes'),
99
createLock: require('./create-lock'),
1010
createNode: require('./create-node'),
11+
errors: require('./errors'),
1112
formatCid: require('./format-cid'),
1213
limitStreamBytes: require('./limit-stream-bytes'),
1314
loadNode: require('./load-node'),

src/core/utils/traverse-to.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const {
1212
FILE_SEPARATOR
1313
} = require('./constants')
1414
const createNode = require('./create-node')
15+
const {
16+
NonFatalError
17+
} = require('./errors')
1518

1619
const defaultOptions = {
1720
parents: false,
@@ -84,15 +87,11 @@ const traverseToMfsObject = (ipfs, path, options, callback) => {
8487
log(`index ${index} pathSegments.length ${pathSegments.length} pathSegment ${pathSegment} lastComponent ${lastComponent}`, options)
8588

8689
if (lastComponent && !options.createLastComponent) {
87-
return done(new Error(`Path ${path.path} does not exist`))
90+
log(`Last segment of ${path} did not exist`)
91+
return done(new NonFatalError('file does not exist'))
8892
} else if (!lastComponent && !options.parents) {
89-
let message = `Cannot find ${path.path} - ${pathSegment} does not exist`
90-
91-
if (options.withCreateHint) {
92-
message += ': Try again with the --parents flag to create it'
93-
}
94-
95-
return done(new Error(message))
93+
log(`Cannot traverse to ${path} - ${pathSegment} did not exist`)
94+
return done(new NonFatalError('file does not exist'))
9695
}
9796

9897
log(`Adding empty directory '${pathSegment}' to parent ${parent.name}`)

src/http/cp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const mfsCp = (api) => {
2929
.catch(error => {
3030
reply({
3131
Message: error.message,
32-
Code: 0,
32+
Code: error.code || 0,
3333
Type: 'error'
3434
}).code(500).takeover()
3535
})

src/http/flush.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const mfsFlush = (api) => {
2020
.catch(error => {
2121
reply({
2222
Message: error.message,
23-
Code: 0,
23+
Code: error.code || 0,
2424
Type: 'error'
2525
}).code(500).takeover()
2626
})

src/http/ls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const mfsLs = (api) => {
3434
.catch(error => {
3535
reply({
3636
Message: error.message,
37-
Code: 0,
37+
Code: error.code || 0,
3838
Type: 'error'
3939
}).code(500).takeover()
4040
})

src/http/mkdir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const mfsMkdir = (api) => {
3131
.catch(error => {
3232
reply({
3333
Message: error.message,
34-
Code: 0,
34+
Code: error.code || 0,
3535
Type: 'error'
3636
}).code(500).takeover()
3737
})

src/http/mv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const mfsMv = (api) => {
2929
.catch(error => {
3030
reply({
3131
Message: error.message,
32-
Code: 0,
32+
Code: error.code || 0,
3333
Type: 'error'
3434
}).code(500).takeover()
3535
})

src/http/read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const mfsRead = (api) => {
4444
stream.once('error', (error) => {
4545
reply({
4646
Message: error.message,
47-
Code: 0,
47+
Code: error.code || 0,
4848
Type: 'error'
4949
}).code(500).takeover()
5050
})

src/http/rm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const mfsRm = (api) => {
2323
.catch(error => {
2424
reply({
2525
Message: error.message,
26-
Code: 0,
26+
Code: error.code || 0,
2727
Type: 'error'
2828
}).code(500).takeover()
2929
})

src/http/stat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const mfsStat = (api) => {
4040
.catch(error => {
4141
reply({
4242
Message: error.message,
43-
Code: 0,
43+
Code: error.code || 0,
4444
Type: 'error'
4545
}).code(500).takeover()
4646
})

test/mkdir.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('mkdir', function () {
5555
parents: false
5656
})
5757
.catch(error => {
58-
expect(error.message).to.contain('foo does not exist')
58+
expect(error.message).to.contain('does not exist')
5959
})
6060
})
6161

test/mv.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('mv', function () {
6767
throw new Error('File was copied but not removed')
6868
})
6969
.catch(error => {
70-
expect(error.message).to.contain(`Path ${source} does not exist`)
70+
expect(error.message).to.contain('does not exist')
7171
})
7272
})
7373

@@ -88,7 +88,7 @@ describe('mv', function () {
8888
throw new Error('Directory was copied but not removed')
8989
})
9090
.catch(error => {
91-
expect(error.message).to.contain(`Path ${source} does not exist`)
91+
expect(error.message).to.contain('does not exist')
9292
})
9393
})
9494

@@ -115,7 +115,7 @@ describe('mv', function () {
115115
throw new Error('Directory was copied but not removed')
116116
})
117117
.catch(error => {
118-
expect(error.message).to.contain(`Cannot find ${source} - ${directory} does not exist`)
118+
expect(error.message).to.contain('does not exist')
119119
})
120120
})
121121
})

test/rm.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('rm', function () {
7676
throw new Error('File was not removed')
7777
})
7878
.catch(error => {
79-
expect(error.message).to.contain(`Path ${file} does not exist`)
79+
expect(error.message).to.contain('does not exist')
8080
})
8181
})
8282

@@ -100,14 +100,14 @@ describe('rm', function () {
100100
throw new Error('File #1 was not removed')
101101
})
102102
.catch(error => {
103-
expect(error.message).to.contain(`Path ${file1} does not exist`)
103+
expect(error.message).to.contain('does not exist')
104104
})
105105
.then(() => mfs.stat(file2))
106106
.then(() => {
107107
throw new Error('File #2 was not removed')
108108
})
109109
.catch(error => {
110-
expect(error.message).to.contain(`Path ${file2} does not exist`)
110+
expect(error.message).to.contain('does not exist')
111111
})
112112
})
113113

@@ -123,7 +123,7 @@ describe('rm', function () {
123123
throw new Error('Directory was not removed')
124124
})
125125
.catch(error => {
126-
expect(error.message).to.contain(`Path ${directory} does not exist`)
126+
expect(error.message).to.contain('does not exist')
127127
})
128128
})
129129

@@ -143,14 +143,14 @@ describe('rm', function () {
143143
throw new Error('File was not removed')
144144
})
145145
.catch(error => {
146-
expect(error.message).to.contain(`Path ${subdirectory} does not exist`)
146+
expect(error.message).to.contain('does not exist')
147147
})
148148
.then(() => mfs.ls(directory))
149149
.then(() => {
150150
throw new Error('Directory was not removed')
151151
})
152152
.catch(error => {
153-
expect(error.message).to.contain(`Path ${directory} does not exist`)
153+
expect(error.message).to.contain('does not exist')
154154
})
155155
})
156156

@@ -170,14 +170,14 @@ describe('rm', function () {
170170
throw new Error('File was not removed')
171171
})
172172
.catch(error => {
173-
expect(error.message).to.contain(`Path ${file} does not exist`)
173+
expect(error.message).to.contain('does not exist')
174174
})
175175
.then(() => mfs.stat(`/${directory}`))
176176
.then(() => {
177177
throw new Error('Directory was not removed')
178178
})
179179
.catch(error => {
180-
expect(error.message).to.contain(`${directory} does not exist`)
180+
expect(error.message).to.contain('does not exist')
181181
})
182182
})
183183
})

test/stat.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('stat', function () {
5757
throw new Error('No error was thrown for a non-existent file')
5858
})
5959
.catch(error => {
60-
expect(error.message).to.contain('Path /i-do-not-exist does not exist')
60+
expect(error.message).to.contain('does not exist')
6161
})
6262
})
6363

0 commit comments

Comments
 (0)