Skip to content
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

Merged
merged 1 commit into from Sep 26, 2018

Conversation

alaibe
Copy link
Contributor

@alaibe alaibe commented Sep 25, 2018

Overview

TL;DR
ENS needs default account

Cool Spaceship Picture

q-ship_from_avengers_infinity_war_003

@alaibe alaibe requested a review from a team September 25, 2018 14:35
Copy link
Contributor

@0x-r4bbit 0x-r4bbit left a 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);
Copy link
Contributor

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))

Copy link
Collaborator

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 :-(

Copy link
Contributor

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).

Copy link
Collaborator

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:
        // ...
    }
  }
});

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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¢.

Copy link
Contributor

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 :)

Copy link
Contributor

@0x-r4bbit 0x-r4bbit left a 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. :)

@iurimatias iurimatias merged commit 0848d81 into next Sep 26, 2018
@iurimatias iurimatias deleted the bugfix/ens-require-default-account branch September 29, 2018 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants