naddison36 / sol2uml

Solidity contract visualisation tool
MIT License
1.12k stars 257 forks source link

storage --data causes "could not detect network" error #163

Closed aspiers closed 10 months ago

aspiers commented 11 months ago

For example:

$ yarn sol2uml storage -f png -hx __gap -n polygon 0xa90dAF1975BA13c26F63976e0Fd73A21F966EE0D -s 0x8A4d7458dDe3023A3B24225D62087701A88b09DD --data
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.7.2)
    at Logger.makeError (/home/adam/myproject/node_modules/@ethersproject/providers/node_modules/@ethersproject/logger/lib/index.js:238:21)
    at Logger.throwError (/home/adam/myproject/node_modules/@ethersproject/providers/node_modules/@ethersproject/logger/lib/index.js:247:20)
    at JsonRpcProvider.<anonymous> (/home/adam/myproject/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:609:54)
    at step (/home/adam/myproject/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
    at Object.throw (/home/adam/myproject/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
    at rejected (/home/adam/myproject/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  reason: 'could not detect network',
  code: 'NETWORK_ERROR',
  event: 'noNetwork'
}
naddison36 commented 10 months ago

Because the --data option is being used, it needs to connect to the chain to get the storage values. By default, it tried to connect to http://localhost:8545. The -u, --url <URL> option can be used to specify the node URL. Alternatively, the URL can be set in the NODE_URL environment variable.

aspiers commented 10 months ago

Ahh thanks, that explains it! So this is another case of ethers.js not giving easy to understand errors. Can sol2uml catch this error and make it more helpful? Although I seem to remember that given the async nature of the error, it may not be possible.

naddison36 commented 10 months ago

Good point in catching this error. The next release will fail with

Error: Failed to connect to blockchain node with url http://localhost:8545.
This is the default url. Use the `-u, --url` option or `NODE_URL` environment variable to set the url of your blockchain node.
    at Command.<anonymous> (/Users/nicholasaddison/Documents/workspaces/sol2uml/src/ts/sol2uml.ts:392:31)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.parseAsync (/Users/nicholasaddison/Documents/workspaces/sol2uml/node_modules/commander/lib/command.js:935:5)
    at async main (/Users/nicholasaddison/Documents/workspaces/sol2uml/src/ts/sol2uml.ts:612:5)
aspiers commented 10 months ago

Great, that's much much better!

naddison36 commented 10 months ago

This has been released in v2.5.16