Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Bug: Truffle fails ungracefully when web3 throws due to an invalid provider. #1724

Closed
1 task done
dan-turner opened this issue Feb 18, 2019 · 5 comments
Closed
1 task done
Labels
error better issue indicates improvement to error messaging

Comments

@dan-turner
Copy link

dan-turner commented Feb 18, 2019


Note: this issue description has been edited from its original content by @benjamincburns to capture our current understanding of the problem:

Issue

Specifying a provider in truffle-config.js is broken with web3 versions >=1.0.0-beta.38. This issue is captured already by web3/web3.js#2266. However, the error thrown by web3 in this case (Error: Please provide an valid Web3 provider) is silenced, likely somewhere in truffle-config.

Steps to Reproduce

The following truffle-config.js does not notify the user of the issue when using [email protected] and all later versions (at time of writing):

const Web3 = require('web3');

const host = "localhost";
const port = 8545

const httpProvider = new Web3.providers.HttpProvider(`http://${host}:${port}`);
const web3 = new Web3(httpProvider);

/* The following line does actually work */
web3.eth.getBlockNumber().then(d => console.log(`Current block: ${d}`));

module.exports = {
  networks: {
    development: {
      provider: function() {
        return httpProvider;
      },
      network_id: '*'
    }
  }
};

Output:

› yarn truffle console --network development --verbose-rpc
yarn run v1.13.0
$ /Users/dan/code/consensys/drizzle/node_modules/.bin/truffle console --network development --verbose-rpc
   > {
   >   "jsonrpc": "2.0",
   >   "id": 1,
   >   "method": "net_version",
   >   "params": []
   > }
Current block: 0
✨  Done in 7.40s.

Expected Behavior

Truffle should inform the user that web3 has failed to accept the provider, either by bubbling up the exception message directly, or by wrapping it in an error of our own.

Actual Results

The provider scenario silently fails.

Environment

  • Operating System: MacOS
  • Ethereum client: Any
  • Truffle version (truffle version): Truffle (unbundled) (core: 5.0.4)
  • node version (node --version): v11.7.0
  • npm version (npm --version): 6.7.0
@benjamincburns
Copy link
Contributor

benjamincburns commented Feb 20, 2019

Users experiencing this problem or other invalid provider issues should pin their web3 dependency to 1.0.0-beta.37 until a workaround for web3/web3.js#2266 is developed. I'd advise users impacted by this issue to voice their concerns over on that thread.

web3/web3.js#2266, which was introduced in [email protected] and at time of writing is still present in the current version of web3.

To confirm this was the cause of the issue, we asked @dan-turner to pin his web3 dependency to 1.0.0-beta.37 (was previously ^1.0.0-beta.35). This corrected the problem. We think that this was likely resolving to some version of web3 that is >=1.0.0-beta.38.

There's an outside chance that this was actually caused by other truffle breaking bugs that were present in [email protected], but these issues were fixed in the 1.0.0-beta.37 release.

@benjamincburns
Copy link
Contributor

Closing this issue, as it's redundant to the one over on the web3 issue tracker.

@benjamincburns
Copy link
Contributor

Actually, it's a bug that the error from web3/web3.js#2266 didn't bubble up to the user in any form. Reopening this case (and lightly editing the description) so we can action that change.

@benjamincburns benjamincburns changed the title Bug: Setting a network provider causes truffle to silently fail Bug: Truffle fails ungracefully when web3 throws due to an invalid provider. Feb 20, 2019
@gnidan gnidan added the error better issue indicates improvement to error messaging label Apr 10, 2019
@gnidan
Copy link
Contributor

gnidan commented Apr 10, 2019

Is this still an issue? We can improve the error handling here to notify unsupported web3 versions. Thanks!

@eggplantzzz
Copy link
Contributor

I believe this got solved a while back with this. Thanks for suggesting this kind of thing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error better issue indicates improvement to error messaging
Projects
None yet
Development

No branches or pull requests

4 participants