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
})

0 commit comments

Comments
 (0)