trufflesuite / truffle-init

Initializer for example Truffle projects
3 stars 11 forks source link

Handle client https errors. #2

Open alcuadrado opened 7 years ago

alcuadrado commented 7 years ago

Node's https.request doesn't execute its callback when there is a client error. If this happened an exception was thrown that crashes the cli process.

Steps to reproduce it:

  1. Go offline
  2. truffle init webpack
  3. The process is terminated with this message:
    
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND raw.githubusercontent.com raw.githubusercontent.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)



There was some attemp to handle this case, but due to `https.request`'s odd API it didn't work as expected. This PR fixes it.
vishharithsa commented 7 years ago

When I run truffle init webpack, I get the following error: events.js:160 throw er; // Unhandled 'error' event ^

Error: getaddrinfo ENOTFOUND raw.githubusercontent.com raw.githubusercontent.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) ~/go-ethereum/myproject$

Tried searching for events.js - not sure where it is located?

Please help

alcuadrado commented 7 years ago

@vishharithsa events.js is part of node, you won't find it in truffle's repos.

Did you have internet connectivity when you got that error? Was your DNS working ok?

vishharithsa commented 7 years ago

@alcuadrado yes, I do. I was able to install npm, truffle without any problems.

In the meantime, my colleague decided to clone the repository since truffle init webpack threw the above mentioned error my instance runs behind a proxy. Is that an issue?

pubmikeb commented 7 years ago

I have exactly the same issue when I send the request to the non existent host. I expect to be able to catch an error and to continue the flow.

Currently, the only way to catch the error that I found is to use: process.on('uncaughtException', exitHandlerCB);

The problem is that this approach forces the process termination.

Is there any way to manage the error without forcing exit?

I use pure Node.js 7.8.0

alcuadrado commented 7 years ago

@vishharithsa Your problem may be related to your proxy. What's your output for curl -vv https://raw.githubusercontent.com/?

@pubmikeb That's because trying to do an HTTPS request to a non-existent host is a client error, and you have to handle those like I did here: https://github.com/trufflesuite/truffle-init/pull/2/files#diff-168726dbe96b3ce427e7fedce31bb0bcR46

pubmikeb commented 7 years ago

@alcuadrado , that worked, thank you. The problem was that I focused on response values, but not on request.

vishharithsa commented 7 years ago

@alcuadrado , following is the output of curl: curl -vv https://raw.githubusercontent.com/