Consensys/surya

Structs alone in a .sol file cause exception

vertti opened this issue ยท 2 comments

Tried surya on my set of contracts:

% surya graph -l contracts/**/*.sol | dot -Tpng > MyContract.png
/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/node_modules/yargs/yargs.js:1109
      else throw err
           ^

TypeError: Cannot read properties of undefined (reading 'push')
    at Object.StructDefinition (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/lib/graph.js:191:42)
    at visit (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:36895:30)
    at /Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:36889:29
    at Array.forEach (<anonymous>)
    at visit (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:36889:10)
    at Object.visit (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:36901:7)
    at _loop (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/lib/graph.js:102:12)
    at graph (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/lib/graph.js:213:18)
    at Object.handler (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/bin/surya:65:19)
    at Object.runCommand (/Users/vertti/.nvm/versions/node/v16.13.1/lib/node_modules/surya/node_modules/yargs/lib/command.js:235:44)

Any idea what could be the cause? Or any way you could improve error messages, if this is something caused by my contracts to narrow down the hunt? Thanks!

Ok, it seems that having any .sol file that contains only a struct will crash surya. So for example add a Fee.sol with contents:

pragma solidity ^0.8.0;

struct FeeSettings {
  uint maxFee;
  uint defaultFee;
  uint protocolTax;
}

and running surya against it will throw the above error message.

GNSPS commented

Sorry for the delay in answering, @vertti !

This had in fact been fixed in the versions for quite a while, but that is not the default version NPM releases. ๐Ÿ˜ž Apologies!

I just released a new major version that includes the previous fixes and should work with globals.

Next time something like this happens feel free to peek into: https://www.npmjs.com/package/surya and download one of the latest dev versions by running npm install -g surya@0.x.y-dev.z.

Apologies! ๐Ÿ˜Š ๐Ÿ™