OpenZeppelin / solidity-docgen

Documentation generator for Solidity projects
MIT License
452 stars 118 forks source link

TypeError: Cannot read properties of undefined (reading 'split') #366

Closed PaulRBerg closed 2 years ago

PaulRBerg commented 2 years ago

Description

I'm getting the following error when running the latest solidity-docgen (the 0.6.0-beta.7 version) in a Hardhat project that uses multiple Solidity compilers:

An unexpected error occurred:

TypeError: Cannot read properties of undefined (reading 'split')
    at decodeSrc (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/utils/read-item-docs.ts:12:41)
    at readItemDocs (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/utils/read-item-docs.ts:6:39)
    at parseNatspec (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/utils/natspec.ts:32:33)
    at natspec (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/accessors.ts:48:24)
    at /Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/accessors.ts:18:35
    at mapValues (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/utils/map-values.ts:4:14)
    at wrapWithAccessors (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/accessors.ts:18:17)
    at itemPartial (/Users/paulrberg/workspace/hifi/monorepo/node_modules/solidity-docgen/src/render.ts:44:35)
    at Object.invokePartial (/Users/paulrberg/workspace/hifi/monorepo/node_modules/handlebars/lib/handlebars/runtime.js:405:12)
    at Object.invokePartialWrapper [as invokePartial] (/Users/paulrberg/workspace/hifi/monorepo/node_modules/handlebars/lib/handlebars/runtime.js:82:39)

Now, to be fair, I'm not 100% sure that it's the multiple compilers that triggers this error, this is just an educated guess. I'm running this in a package in a monorepo, a monorepo in which there are other packages with no multiple compilers in which solidity-docgen works just fine.

How to Reproduce

Fork the hifi-finance/hifi repo, switch to the docs/flash-swap branch, install dependencies with yarn, cd into the packages/flash-swap directory, run yarn generate:docs.

Environment

frangio commented 2 years ago

I have trouble reproducing because it needs the various environment variables (e.g. INFURA_API_KEY). I can edit the config to remove that but do you have another way to handle that?

PaulRBerg commented 2 years ago

Well removing the environment variables might trigger some unintended side effects, it'd be best to just add a .env file with the values required there.

Here are some dummy values that you could use:


ETHERSCAN_API_KEY="EI4VPBI74B3N2PJVT9WQ9RIW4YJCSP5ZAC"
INFURA_API_KEY="defba93b47f748f09fcead8282b9e58e"
MNEMONIC="soul business photo bean pigeon impose defy team fire matter retire gap"
POLYGONSCAN_API_KEY="VBY7ZD2G2ZU3QFD7HEHVPNKI9PSVWYNT2Y"
frangio commented 2 years ago

The issue was due to contracts using Solidity 0.5, which has a different AST structure around documentation. The AST types at solidity-ast only support 0.6 onwards. But anyway it's fixed in the last release.

PaulRBerg commented 2 years ago

Can confirm that it works now. Thanks!