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

feat: show which link does not exist on ipfs.cat #1270

Closed
wants to merge 5 commits into from

Conversation

youngnicks
Copy link

Closes #1145.

For interface-ipfs-core test to pass, the corresponding test there needs to be updated to be similar to below as one version of running tests has an error message prepended with Failed to cat file: Error:, causing the test to fail.

expect(err.message).to.contain(
  'no link named "does-not-exist" under Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
)

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @youngnicks. This PR is missing, however, the case for when on a path /a/b/c, c doesn't exist on b, it is only covering the whole path a/b/c.

@youngnicks
Copy link
Author

Thanks for the feedback @diasdavid. I'll work on getting that functionality added as well as appropriate tests.

@youngnicks
Copy link
Author

@diasdavid I added logic to determine which node in the path is missing and updated the error message. I want to get some feedback on how I did this as it could have performance hits on nodes containing lots of files. If this is acceptable, I will add a test case for the scenario when part of the path doesn't exist. If this isn't acceptable, I'm going to have to put logic in a higher function to determine where the missing path is.

expect(err).to.exist()
expect(message).to.eql(
'no link named "dummy" under QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
)
Copy link
Member

Choose a reason for hiding this comment

The 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 /a/b/c/d) and you will see that after the first level, this PR fails.

Copy link
Author

Choose a reason for hiding this comment

The 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 no link named "c/d" under a/b to provide more context to as to what the requested file is.

@youngnicks
Copy link
Author

@diasdavid I added an additional test for nestedness. Both tests are passing. Is the format of the nested error correct, or should it be saying something different?

@youngnicks
Copy link
Author

@diasdavid After playing around with go-ipfs, I noticed how it handles this situation and updated the code to provide the same error.

@daviddias daviddias requested a review from pgte March 21, 2018 03:56
@daviddias
Copy link
Member

@pgte mind reviewing this PR and help @youngnicks get it completed?

Copy link
Contributor

@pgte pgte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is much better than before, but, thanks to @youngnicks work here, I think there's the opportunity here to present a completely unambiguous error message.

.catch((err) => {
const message = err.stderr.match(/^Error:(?: Failed to cat file: Error:)? (.*)$/m)[1]
expect(message).to.eql(
'no link named "wrong-dir" under QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the error to say something like either:

  • "no file named "wrong-dir" under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs/docs" or
  • "no file named "init-docs/docs/wrong-dir" under QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2" or

Would any of these be possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that I'm using the term file and not link, on purpose ;)

const filterFile = (file) => {
if (file.path === ipfsPath.substring(0, file.path.length)) {
if (file.depth > bestMatch.depth) {
bestMatch = file
Copy link
Contributor

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)

Copy link
Author

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 use pathComponents 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

Copy link
Contributor

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! 👍

@youngnicks
Copy link
Author

I modified the error messages to be more specific and added a new one which informs the user when a file is trying to be used as a directory.

@pgte Can you please take a look at this and let me know if you would like any other changes?

@pgte
Copy link
Contributor

pgte commented Mar 23, 2018

@youngnicks Error messages look great!

To move on, I guess interface-ipfs tests need to be updated, right?

@youngnicks
Copy link
Author

@pgte Thanks! I already submitted a pull request for interface-ipfs-core. I'm just having issues testing it with js-ipfs-api. For some reason I'm getting the errors formatted in my prior commit and not the new ones.

ipfs-inactive/interface-js-ipfs-core#241

@daviddias daviddias changed the title Show which link does not exist on ipfs.cat feat: show which link does not exist on ipfs.cat May 29, 2018
@daviddias
Copy link
Member

Hi! js-ipfs master just got a whole new set of automated tests with #2528, #2440 and also running some of the test suites from our early testers (hi5 to @achingbrain for setting it all up!). Would you mind rebasing the master branch on this PR to ensure it runs all the latest tests? Thank you!

@jacobheun
Copy link
Contributor

Closing as this is stale and there have been significant changes since this was created

@jacobheun jacobheun closed this Feb 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should specify which link didn't exist on ipfs.cat
4 participants