Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

maker.authenticate does not throw an error when the network is not accessible #75

Open
bryanwb opened this issue Jan 10, 2019 · 5 comments

Comments

@bryanwb
Copy link

bryanwb commented Jan 10, 2019

await maker.authenticate() silently fails when the target network is not accessible.

@levity
Copy link
Contributor

levity commented Jan 16, 2019

Can you provide more detail about the situation? When I try this with a network address that is not listening, I get the expected output, e.g.:

const Maker = require('@makerdao/dai')
const url = 'http://localhost:9999'

async function main() {
  const maker = Maker.create('http', { url })
  try {
    await maker.authenticate()
  } catch (err) {
    console.log(err)
  }
}

main()

outputs

{ [Error: connect ECONNREFUSED 127.0.0.1:9999] message: 'connect ECONNREFUSED 127.0.0.1:9999', code: -32603 }

Does await maker.authenticate() actually complete, or does it just hang? I would expect the latter behavior (with an eventual timeout) if you try to connect to an address that is unresponsive, e.g. if changing url above to http://google.com:9999.

@levity
Copy link
Contributor

levity commented Jan 17, 2019

Thanks for creating dai-shell, btw! Sorry it took us so long to respond to you. Guess you must have sorted things out in the meantime :)

@bryanwb
Copy link
Author

bryanwb commented Jan 17, 2019

alright, the fault was mine. I had copied the configuration for Maker settings for the test network from here https://github.com/makerdao/dai.js/blob/dev/test/integration/dai.spec.js#L59-L77 rather than from the official docs. W/ that configuration, authenticate() doesn't return an error if it fails to connect.
my bad!

@bryanwb bryanwb closed this as completed Jan 17, 2019
@bryanwb
Copy link
Author

bryanwb commented Jan 17, 2019

OK, I was able to reproduce the error by slightly modifying your script. Adding privateKey to the settings caused the connection error to be dropped.

the following

# tmp.js
const Maker = require('@makerdao/dai')

async function main() {
  //const settings = {url: 'http://localhost:2000'};
  const settings = {url: 'http://localhost:2000', privateKey: '0xxxxxxx'};
  const maker = Maker.create('http', settings);
  try {
    await maker.authenticate()
  } catch (err) {
    console.log(err)
  }
  console.log('after authentication')
}

main()

outputs the following when the local 'test' network is not running

$ node tmp.js
Web3 is initializing...
Web3 is connecting...

note that after authentication is not displayed

@bryanwb bryanwb reopened this Jan 17, 2019
@levity
Copy link
Contributor

levity commented Jan 17, 2019

interesting; i can reproduce that too. will look into it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants