latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
721 stars 180 forks source link

Usability: Better errors on compilation #3003

Open qbzzt opened 1 month ago

qbzzt commented 1 month ago

When I issue pnpm build in packages/contract, and I have a syntax error, I often get something I can't understand, such as

qbzzt1@penguin:~/zk/packages/contracts$ pnpm build

> contracts@0.0.0 build /home/qbzzt1/zk/packages/contracts
> mud build

(node:21973) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
null
/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:9347
        throw new RangeError("index parameter must be between >= 0 and <= number of children.");
              ^

RangeError: index parameter must be between >= 0 and <= number of children.
    at SimpleStatementContext.getChild (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:9347:15)
    at ASTBuilder.visitSimpleStatement (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:35689:27)
    at SimpleStatementContext.accept (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:33857:22)
    at ASTBuilder.visit (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:17669:19)
    at ASTBuilder.visitStatement (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:35686:17)
    at /home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:35722:51
    at Array.map (<anonymous>)
    at ASTBuilder.visitBlock (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:35722:35)
    at ASTBuilder.visitFunctionDefinition (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:35761:20)
    at FunctionDefinitionContext.accept (/home/qbzzt1/zk/node_modules/.pnpm/@solidity-parser+parser@0.16.2/node_modules/@solidity-parser/parser/dist/index.cjs.js:32766:22)

Node.js v20.15.0
 ELIFECYCLE  Command failed with exit code 1.

When Solidity compilation fails, can we try to do a forge build and get the error message from that? It makes a lot more sense.

qbzzt1@penguin:~/zk/packages/contracts$ forge build
[⠒] Compiling...
[⠊] Compiling 73 files with Solc 0.8.24
[⠒] Solc 0.8.24 finished in 927.14ms
Error: 
Compiler run failed:
Error (2314): Expected ';' but got 'uint8'
  --> src/systems/GameSystem.sol:19:11:
   |
19 |     const uint8 height = Configuration.getHeight();
   |           ^^^^^
holic commented 1 week ago

this also happens when you use a reserved keyword inside e.g. a table config