-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: show which link does not exist on ipfs.cat #1270
Changes from all commits
3b2d9fe
87ab4bb
aa2d6a6
4f3ec22
8b6f79b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,10 +319,47 @@ describe('files', () => runOnAndOff((thing) => { | |
}) | ||
|
||
it('cat non-existent file', () => { | ||
return ipfs('cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB/dummy') | ||
return ipfs('cat QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU/dummy') | ||
.then(() => expect.fail(0, 1, 'Should have thrown an error')) | ||
.catch((err) => { | ||
const message = err.stderr.match(/^Error:(?: Failed to cat file: Error:)? (.*)$/m)[1] | ||
expect(err).to.exist() | ||
expect(message).to.eql( | ||
'no file named "dummy" under QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU' | ||
) | ||
}) | ||
}) | ||
|
||
it('cat specifies missing directory in a nested link', () => { | ||
return ipfs('cat QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs/wrong-dir/dummy') | ||
.then(() => expect.fail(0, 1, 'Should have thrown an error')) | ||
.catch((err) => { | ||
const message = err.stderr.match(/^Error:(?: Failed to cat file: Error:)? (.*)$/m)[1] | ||
expect(message).to.eql( | ||
'no directory named "wrong-dir" under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs' | ||
) | ||
}) | ||
}) | ||
|
||
it('cat specifies missing file in a nested link', () => { | ||
return ipfs('cat QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs/dummy') | ||
.then(() => expect.fail(0, 1, 'Should have thrown an error')) | ||
.catch((err) => { | ||
const message = err.stderr.match(/^Error:(?: Failed to cat file: Error:)? (.*)$/m)[1] | ||
expect(message).to.eql( | ||
'no file named "dummy" under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs' | ||
) | ||
}) | ||
}) | ||
|
||
it('cat specifies a link is not a directory', () => { | ||
return ipfs('cat QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs/index/dummy') | ||
.then(() => expect.fail(0, 1, 'Should have thrown an error')) | ||
.catch((err) => { | ||
const message = err.stderr.match(/^Error:(?: Failed to cat file: Error:)? (.*)$/m)[1] | ||
expect(message).to.eql( | ||
'"index" is a file not a directory under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs' | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feature is still not complete. Please add tests for multiple levels of nestedness (i.e There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I was more asking if this would be an acceptable location for this logic, knowing that it could possibly have a performance hit when there is a large amount of files on a node. What should the error message show when a middle level is missing? I am thinking the message should be |
||
}) | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of replacing, could we retain the complete path of the best match to support more relevant error messages? (See my previous comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think replacing here is still okay as the depth tells us how many nodes
bestMatch
matches and we can usepathComponents
to build the path. This is essentially what I was doing earlier on in the pull request. I thought of defining if a directory or file was missing, but it wasn't part of the spec so I left it the way it was.We could have another scenario where a user tries to specify a file under a file thinking it is a directory. What do you think of these errors?
Missing directory
no directory named "wrong-dir" under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs
Missing file
no file named "does-not-exist" under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs
File instead of directory
"actually-a-file" is a file not a directory under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youngnicks this would be even better! 👍