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

Commit 4e6a6ee

Browse files
committed
feat: better error message on ipfs cat
`ipfs cat <hash>/wrong-dir/wrong-file` previously returned: 'No such file'. this commit changes the error message to: 'no file named "wrong-dir/wrong-file" under <hash>' License: MIT Signed-off-by: Nitin Patel <[email protected]>
1 parent 1c07779 commit 4e6a6ee

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/core/components/files-regular/cat-pull-stream.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ module.exports = function (self) {
1414
options = options || {}
1515

1616
ipfsPath = normalizePath(ipfsPath)
17+
1718
const pathComponents = ipfsPath.split('/')
1819
const fileNameOrHash = pathComponents[pathComponents.length - 1]
20+
const cid = pathComponents[0]
21+
const filePath = pathComponents.slice(1).join('/')
1922

2023
if (options.preload !== false) {
2124
self._preload(pathComponents[0])
@@ -33,7 +36,7 @@ module.exports = function (self) {
3336
}
3437

3538
if (!files.length) {
36-
return d.abort(new Error('No such file'))
39+
return d.abort(new Error(`no file named "${filePath}" under ${cid}`))
3740
}
3841

3942
const file = files[0]

test/cli/files.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ describe('files', () => runOnAndOff((thing) => {
436436
.then(() => expect.fail(0, 1, 'Should have thrown an error'))
437437
.catch((err) => {
438438
expect(err).to.exist()
439+
expect(err.stdout).to.contain('no file named "dummy" under QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
440+
})
441+
})
442+
443+
it('cat non-existent file (nested)', () => {
444+
return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB/wrong-dir/wrong-file')
445+
.then(() => expect.fail(0, 1, 'Should have thrown an error'))
446+
.catch((err) => {
447+
expect(err).to.exist()
448+
expect(err.stdout).to.contain('no file named "wrong-dir/wrong-file" under QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
439449
})
440450
})
441451

0 commit comments

Comments
 (0)