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

_lookupNode callback to use standard error, response pattern #83

Merged
merged 1 commit into from
Mar 19, 2019

Conversation

zmitton
Copy link
Contributor

@zmitton zmitton commented Feb 26, 2019

PR #82 broken into 2 pieces

This one doesn't deal with proofs. It just standardizes the callback pattern of _lookupNode

@coveralls
Copy link

coveralls commented Feb 26, 2019

Coverage Status

Coverage decreased (-0.6%) to 93.092% when pulling 0cd83dc on zmitton:fix-17 into 768eac1 on ethereumjs:master.

Copy link
Member

@holgerd77 holgerd77 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 PR! 👍

This has various linting errors (like e.g. if(e)).

I was puzzled why this has not been catched by linting CI command and did some deeper research. This has actually its root in the .gitignore file having too generic patterns for the specific files from src which are currently build (currently) to the root folder, like baseTrie.js.

This is actually also matching src/baseTrie.js, see this answer on StackOverflow, and was just not discovered since all these files are already added to git and therefore taken along.

All these paths/patterns from baseTrie.js onwards have to be changed in the following way:

  • baseTrie.js -> /baseTrie.js

Then linting will be reactivated. Can you add this here and fix the three additional linting errors which will occur together with the linting errors from your code?

Thanks! 😄 (that was actually a tough one to discover! 😛)

@zmitton
Copy link
Contributor Author

zmitton commented Feb 28, 2019

@holgerd77 I had forgotten to run the linter.

.gitignore Outdated Show resolved Hide resolved
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Some small changes, otherwise looks good! 😄

src/baseTrie.js Outdated
@@ -141,9 +141,11 @@ module.exports = class Trie {

if (value) {
value = new TrieNode(rlp.decode(value))
} else {
err = 'Missing node in DB'
Copy link
Member

Choose a reason for hiding this comment

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

Can we have this wrapped in an Error object here?

src/baseTrie.js Outdated
@@ -375,7 +377,8 @@ module.exports = class Trie {
return onDone()
}

this._lookupNode(root, node => {
this._lookupNode(root, (e, node) => {
if (e) { return onDone(e, node) }
Copy link
Member

Choose a reason for hiding this comment

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

Can you do this with three-line code style to be consistent e.g. with the code directly below (sorry for the nitpicking 😄)?

src/baseTrie.js Outdated Show resolved Hide resolved
src/baseTrie.js Outdated
@@ -434,7 +438,8 @@ module.exports = class Trie {
childKey.push(childIndex)
const priority = childKey.length
taskExecutor.execute(priority, taskCallback => {
self._lookupNode(childRef, childNode => {
self._lookupNode(childRef, (e, childNode) => {
if (e) { return cb(e, node) }
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

src/baseTrie.js Outdated Show resolved Hide resolved
@s1na
Copy link
Contributor

s1na commented Mar 3, 2019

Thanks for the PR!

Just for clarity: how does the behaviour of get change after this PR? If the given key (or any other key on the path) is not in db, it will return an error in the callback as opposed to just returning a null value? Can you please update the get jsdocs and highlight these edge cases?

@holgerd77
Copy link
Member

Hi Zac, if you feel my 1-vs-3-line if clause comments are too nitty-gritty you have my full understanding and feel free to ignore 😄, but can you address the comment from @s1na? That would be great, then we can merge here, integrate your other fixes and eventually do a release on the library.

@zmitton
Copy link
Contributor Author

zmitton commented Mar 14, 2019

Things have gotten busy. I will update this weekend though. And no worries @holgerd77, just wanted to let all the suggestions come in before attempting make another commit.

@s1na I dont think the behavior of get should change at all regarding a value being null. The Error should only be thrown if the trie's db is missing an underlying node which would mean the trie is corrupt (or if it is a proof, the proof is corrupt).

@s1na
Copy link
Contributor

s1na commented Mar 14, 2019

let all the suggestions come in

I think it already looks good, and we can merge after you apply @holgerd77 comments. Thanks!

The Error should only be thrown if the trie's db is missing an underlying node

Yeah that's what I meant, I was just trying to say maybe we should add this to the docs, because previously even in this case error would have been null. But just checked again, and the docs already say that the callback can return an error, so all good.

Copy link
Contributor

@s1na s1na left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @zmitton!

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.

4 participants