foundry: bug(`forge script`): `failed to read artifact source` with lib dependencies that include files without a matching contract name

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 (0ae39ea 2023-12-11T00:27:32.487222000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

Running forge script in a repo that has a dependency with .sol files that don’t contain a contract (e.g. the file contains only error definitions or constants) results in an error like

thedavidmeister@davids-iMac polytrade % forge script scripts/OrderBookNPE2.s.sol                
[⠒] Compiling...
No files changed, compilation skipped
Error: 
failed to read artifact source file for `lib/rain.interpreter/src/error/ErrBitwise.sol:ErrBitwise`

Context:
- Error #0: failed to read from "/Users/thedavidmeister/Code/polytrade/src/error/ErrBitwise.sol": No such file or directory (os error 2)
- Error #1: No such file or directory (os error 2)

This error can be worked around by adding an empty contract like contract ErrBitwise {} in the file that forge is complaining about

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 28 (3 by maintainers)

Most upvoted comments

Any time I get an error with artifacts, the first step I take is forge clean followed by forge build

Hi. I had the same problem and solved it by clearing foundry’s cache with the following command:

forge clean

See forge-clean.

using

forge clean 

worked for me

had similar issue running op-stack deployment scripts. No matching artifact found revert to an early foundry version fixed it foundryup -v nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a

@zhiqiangxu could you provide a way to reproduce this issue consistently? thank you!

Sorry I can’t,last time when I was debugging from source code, the issue suddenly went away, I guess it’s a random bug with cache. That’s all I can say.

forge clean doesn’t work for me.

It seems a random bug, but is now always showing up on my machine:

image

Clearly the correct path should be L2/interfaces/ICrossL2Inbox.sol, but it’s looking for L2/ICrossL2Inbox.sol.

I’ve already upgraded to the latest version:

% forge --version                                                                       
forge 0.2.0 (883bb1c 2024-09-25T00:24:44.893538000Z)

Noticed the bug popped up when changing pathnames and them sticking but not updating in foundry.

Any time I get an error with artifacts, the first step I take is forge clean followed by forge build

This resolved the issue for me

Any time I get an error with artifacts, the first step I take is forge clean followed by forge build

Any time I get an error with artifacts, the first step I take is forge clean followed by forge build

This worked for me

so an annoyable bug. With no fix from the team.