Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

100% (line) coverage. #9

Merged
merged 10 commits into from
Apr 19, 2016
Merged

100% (line) coverage. #9

merged 10 commits into from
Apr 19, 2016

Conversation

hackergrrl
Copy link
Contributor

@hackergrrl hackergrrl commented Apr 14, 2016

Woohoo! This PR contains both important bugfixes and also test cases that prove their newfound correctness!

Important: this also changes the getBlock() callback semantics to NOT populate err when a block cannot be found. It is this hacker's belief that "not found" is not an error case. The README is also updated to reflect this!

This gets us to 100% line coverage. There are a few tiny branches still not covered, but they are both a) trivial, and b) would require test case bloat / noise to cover them.

Addresses ipfs/js-ipfs#115.

@daviddias
Copy link
Member

Thank you @noffle :):)

I'm not sure about the hacker belief you describe. AFAIK, ENOENT is a thing and I've checked the fs module and abstract-blob-store and both of them yield a error if a thing is not found locally.

fs

> fs.readFile('__dirname' + '/random-file', {}, (err, data) => {if (err) {console.log('->', err)}})
undefined
> -> { [Error: ENOENT: no such file or directory, open '__dirname/random-file']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '__dirname/random-file' }

abstract-blob-store

https://github.com/maxogden/abstract-blob-store/blob/master/tests/read-write.js#L52-L65

@hackergrrl
Copy link
Contributor Author

It's true: we could check Error.code for ENOENT, but this is an awkward way to check for non-existence (it IS an error). I'd feel better about it if we had an API call for checking block existence as well -- much like how blob-stores have exists().

This raises the question of how to handle partial failure in getBlocks. One way is to accumulate an array of errors to return alongside the array of blocks.

@hackergrrl
Copy link
Contributor Author

I poked at some folks on #stackvm and thought some more about this, and I agree that getBlock returning an error here is reasonable: if the user is calling getBlock then they are making an implicit assertion that it already exists. If it doesn't, an error is a reasonable outcome to codify this contradictory state.

Now to decide how getBlocks (plural) should behave. It could simply swallow ENOENTs and return whatever blocks come back, or it could fail noisily the instant one of the requested blocks is not present.

@hackergrrl
Copy link
Contributor Author

Can we config the coveralls bot to not post on the issue thread? It's noisy and the coverage notes are already included in the merge results box at the bottom.

@whyrusleeping
Copy link
Member

agreed. its super noisy.

@daviddias
Copy link
Member

Agreed. Removed the coveralls comments (if you happen to see another one in another repo, I might have missed).

@noffle in relation to getBlocks, what we can do is to return an array of objects with {multihash:<>, block: <>} and in the ones that it was not possible to retrieve, we set it to undefined, so that in a IPFS core get several blocks call, they can be first retrieved by the repo and those who are missing can be populated by bitswap or other mechanism.

@hackergrrl
Copy link
Contributor Author

@diasdavid it seems strange if getBlocks doesn't return an error state on not-found, but getBlock does. I'd really want us to be consistent across these APIs.

@daviddias
Copy link
Member

Ok, let's put the {multihash: <>, err: <>} for the ones that fail to fetch from the repo

@hackergrrl
Copy link
Contributor Author

Updated impl, tests, and docs. This is a breaking API change, so please bump the major after PRing. :)

@coveralls
Copy link

Coverage Status

Coverage increased (+20.8%) to 100.0% when pulling 58f1191 on noffle:coverage into a907f86 on ipfs:master.

@whyrusleeping
Copy link
Member

@coveralls your presence is unwelcome here

@hackergrrl
Copy link
Contributor Author

@coveralls unsubscribe

@daviddias
Copy link
Member

Disabled coveralls commenting (missed this one, sorry).

On bumping up major version. AFAIK and what I've been considering best practice is that until 1.0.0, the module should be handled as alpha/beta, so what I would do in this scenario is bumping minor. If we were already at major versions (after having declared that we had something stable) I would bump the major. Sounds good? Thoughts? @dignifiedquire you might have a opinion on this too.

@@ -149,12 +149,27 @@ Asynchronously adds an array of block instances to the underlying repo.
#### bs.getBlock(multihash, callback(err, block))

Asynchronously returns the block whose content multihash matches `multihash`.
Returns an error (`err.code === 'ENOENT'`) if the block does not exist.
Copy link
Member

Choose a reason for hiding this comment

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

nice :)

@dignifiedquire
Copy link
Member

:D :D I never have opinions ;)
But if you ask I'll give you some, I usually follow the convention node.js used before 1.0 if there is no 1.0 yet, meaning

  • minor releases can mean breaking changes
  • patch releases can include features and bug fixes, but should be backwards compatible.

@daviddias
Copy link
Member

thank you @dignifiedquire :)

@noffle would you agree with that approach? :)

@hackergrrl
Copy link
Contributor Author

Whoops, I didn't realize we were pre-1.0.0. Yeah -- bump whatever freely. 😀

@daviddias
Copy link
Member

awesome! :D

@daviddias daviddias merged commit 0c55fdc into ipfs:master Apr 19, 2016
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.

None yet

5 participants