crytic / slither-action

GNU Affero General Public License v3.0
127 stars 19 forks source link

Failing with FileNotFoundError: [Errno 2] No such file or directory: '/github/workspace/artifacts/build-info' #56

Open Phips0812 opened 1 year ago

Phips0812 commented 1 year ago

I am using crytic/slither-action@v0.3.0 within my GitHub Actions and it worked like a charm until a few day ago.

Since it few days it's failing with the following error. I think it is related that one step is not waiting for the other as it can also be seen in the snippet below. npx hardhat compile --force is running and normally there should come the output of the compilation. However it directly tries to find /github/workspace/artifacts/build-info which is not there yet.

'npx hardhat compile --force' running
Automining active
Automining active
Downloading compiler 0.8.16

You are using a version of Node.js that is not supported by Hardhat, and it may work incorrectly, or not work at all.

Please, make sure you are using a supported version of Node.js.

To learn more about which versions of Node.js are supported go to https://hardhat.org/nodejs-versions

Traceback (most recent call last):
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 837, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 90, in process_all
    compilations = compile_all(target, **vars(args))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 643, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 195, in compile
    hardhat_like_parsing(crytic_compile, self._target, build_directory, hardhat_working_dir)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 49, in hardhat_like_parsing
    os.listdir(build_directory), key=lambda x: os.path.getmtime(Path(build_directory, x))
FileNotFoundError: [Errno 2] No such file or directory: '/github/workspace/artifacts/build-info'
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 837, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/slither/lib/python3.9/site-packages/slither/__main__.py", line 90, in process_all
    compilations = compile_all(target, **vars(args))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 643, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 195, in compile
    hardhat_like_parsing(crytic_compile, self._target, build_directory, hardhat_working_dir)
  File "/opt/slither/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 49, in hardhat_like_parsing
    os.listdir(build_directory), key=lambda x: os.path.getmtime(Path(build_directory, x))
FileNotFoundError: [Errno 2] No such file or directory: '/github/workspace/artifacts/build-info'
elopez commented 1 year ago

HI @Phips0812, thanks for the report! We have seen this happening a few times in the recent weeks but we have not been able to pinpoint what causes it. There have been no new Slither nor action releases in these last few days, so it's probably not something that changed in Slither or Crytic-compile. Have you upgraded anything else on your project recently? (e.g. solc version in your config, hardhat version, npm dependencies, node version in CI, etc?)

For reference, this is the code that invokes Hardhat. It uses communicate() which should wait until the process exits, so it's possible Hardhat is just failing silently and not producing the artifacts:

https://github.com/crytic/crytic-compile/blob/master/crytic_compile/platform/hardhat.py#L177-L193

I see there is also this warning being printed from your Hardhat:

You are using a version of Node.js that is not supported by Hardhat, and it may work incorrectly, or not work at all.

Please, make sure you are using a supported version of Node.js.

To learn more about which versions of Node.js are supported go to https://hardhat.org/nodejs-versions

If you could try using a supported version (see the node-version option in the action to change it) and confirm if you can reproduce the issue still, that would be great.

Thanks again!

frangio commented 1 year ago

We get this too... (Example)

It doesn't happen consistently, so it sounds like a race condition of some kind.

elopez commented 1 year ago

Looking at the Hardhat issue tracker, this might be related: https://github.com/NomicFoundation/hardhat/issues/3877

Phips0812 commented 1 year ago

@elopez thanks for the quick response! I will try to change to a supported node version asap.

However some more info: Like mentioned by @frangio this also happens randomly on our side. Sometimes if I rerun the GitHub Actions it works in the second or third run.

mattiascaricato commented 1 year ago

Same issue here. The only difference is that – so far – it happens always, not randomly, as mentioned above. I'm using slither-action v0.3.0 with latest Node LTS (18) + Solidity compiler v0.8.17

Regarding this error: You are using a version of Node.js that is not supported by Hardhat, and it may work incorrectly, or not work at all.

All you need to do is add node's version when you are defining the step. Like this:

- name: Run Static Analysis (Slither)
  uses: crytic/slither-action@v0.3.0
  with:
    node-version: 18
Phips0812 commented 1 year ago

Setting the node-version for slither to 18.15 seems to fix this for now:

- name: Run Static analysis
  uses: crytic/slither-action@v0.3.0
  with:
    node-version: 18.15

Thanks @frangio for the mentioned commit.

0xmichalis commented 1 year ago

We also started seeing this issue recently with crytic/slither-action@0.2.0. It occurs inconsistently.