foundry: forge coverage: "No such file or directory (os error 2)"

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (0d44687 2022-07-01T00:27:19.177599Z)

What command(s) is the bug in?

forge coverage

Operating System

macOS (Intel)

Describe the bug

forge coverage results in this error saying a file isn’t found, but I’ve confirmed it exists at that location. 🤔

❯ forge coverage
[⠒] Compiling...
[⠢] Compiling 4 files with 0.8.7
[⠆] Compiling 69 files with 0.8.14
[⠰] Compiling 1 files with 0.8.4
[⠒] Solc 0.8.4 finished in 16.49ms
[⠰] Solc 0.8.7 finished in 2.23s
[⠃] Solc 0.8.14 finished in 10.15s
Compiler run successful
Analysing contracts...
Error: 
failed to read from "node_modules/.pnpm/@openzeppelin+contracts-upgradeable@4.4.2/node_modules/@openzeppelin/contracts-upgradeable/interfaces/IERC165Upgradeable.sol": No such file or directory (os error 2)

Context:
- No such file or directory (os error 2)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I am now able to run forge coverage on the same project so we might close this if @gigamesh agrees.

I am now able to run forge coverage on the same project so we might close this if @gigamesh agrees.

How have you fixed this issue @gigamesh ? Experiencing the same… cc @elenadimitrova @onbjerg

For anyone running into this issue, double check if your ~/.svm has become corrupted!

Especially so if you are using Apple M1 or M2 silicon, as compiling smart contracts written in Solidity 0.8.5 or older can fail when the z3 theorem prover isn’t installed, although it seems most Macbooks will handle this by default. I believe the issue in my case is that I run Linux in a VM on Apple silicon, so the z3 theorem prover was not present.

Here is the blurb from the Foundry Book docs about how this can arise, though in my case it was very sneaky as it only errored with “No such file or directory (os error 2)” and doesn’t blame the compiler. image

Reproducible example of broken, unrunnable scripts for Linux VMs: https://github.com/0xStation/groupos/tree/debug

I have almost absolutely the exact problem you are describing - I am using solidity 0.8.20. On top of that I’m developing in a docker container and thus have a Linux VM on top of Apple Silicon. The error also corresponds to yours: No such file or directory (os error 2). I tried installing z3 in the container as well as on the host but the issue is still the same. Would you mind explaining what you did to fix it in a bit more detail?

forge 0.2.0 doesn’t say much, I need the commit hash after the version number as well. All nightlies after early this year use 0.2.0 as their version number

Please open up a new issue with some steps I can take to reproduce, I don’t really know where to start looking in that repository’s structure. From what I can tell in your justfile forge coverage is never invoked (DAPP_COVERAGE is not a thing in Forge)

Hi @gigamesh, as mentioned elsewhere coverage is not stable (and is not released as such), so it will take a while for me to turn around on this as there are other bugs that are a bit more pressing re: coverage. I’m currently doing a big change to coverage, so maybe it will “fix itself” after that.

I’m unsure why it can’t read that path specifically, I haven’t spend a lot of time debugging it yet, so I don’t have a very in-depth response for you right now, apologies