New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning if no default account for ens #906
Conversation
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.
Left a comment!
@@ -229,6 +236,10 @@ __embarkENS.lookup = function (address, callback) { | |||
__embarkENS.registerSubDomain = function (name, address, callback) { | |||
callback = callback || function () {}; | |||
|
|||
if (!web3.eth.defaultAccount) { | |||
return callback(defaultAccountNotSetError); |
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.
Shouldn't those be at least instance of Error
? e.g.
return callback(new Error(defaultAccountNotSetError))
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.
This is a huge pet peeve of mine too, @PascalPrecht. Each module should define their own errors as constants and pass those around :-(
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.
Yes, and I think it's enough to first just upgrade this code to use Error
type in the first place. We can then introduce custom errors in the future, in case we need them.
It's just that, the way it looks like to me right now, is that simply because callback()
gets called with the message as first parameters, call sides will probably simply expect the first param to be an error a la:
doSomething((err, data) => {
if (err) {
// whoops
}
// do something with data
})
But even then err
is just a string. Semantically it should at least be Error
IMO.
For consistency reasons though, I can see why @alaibe went for just using a string. But maybe this is a good opportunity to change to Error
in all places (in this module).
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.
Oh, totally. He's keeping consistent, I'm talking about wishful thinking in the future. Something along the lines of:
doSomething((err, data) => {
if(err) {
switch(err) {
case ThisModule.ThisError:
// ...
case ThisModule.ThatError:
// ...
}
}
});
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.
It's a bit of a band-aid, but we do have:
https://github.com/embark-framework/embark/blob/develop/lib/utils/utils.js#L484
If an error passed to a callback is destined for logging, it can be run through that utility function if the type isn't known.
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'm all for that! 👌
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.
For completeness-sake this (very old) article pretty much sums up the best practices: https://humanwhocodes.com/blog/2009/03/10/the-art-of-throwing-javascript-errors-part-2/
This can be applied to promise-based/async/await APIs as well. Really what it boils down to is that errors are actual errors, so they can be handled correctly if needed.
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 am all up for doing changes you suggest here.
However this is a PR for 3.2 being released very soon.
Also this is a bug fix. I think all these awesome ideas:
- async generators
- await/async
- Error
Deserve at least a real story.
Being that close to 3.2 I just wanted to do the minimum vital change. Not being lazy but just wanted to make sure to break the least possible things.
What do you think?
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 agree re: min vital change — I consider/ed the other ideas to be for the future, just thought I'd throw in my 2¢.
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.
Absolutely! This can be done in the near future.
I've created #911 so we don't forget :)
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.
This LGTM as per discussion. I've created #911 so we can keep track of this. :)
Overview
TL;DR
ENS needs default account
Cool Spaceship Picture