foundry
foundry copied to clipboard
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?
- [X] 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
+1 on this. Also receiving the same error. Using forge 0.2.0 as well
For context, I was able to fix this error by changing the imports in my dependency contracts.
Switching from import {Data} from "src/some/path/file.sol"
to import {Data} from "./some/path/file.sol"
is what fixed it for me.
So im assuming this bug has to do with the way remappings are handled in scripts?
same. haven't found a fix yet.
repo is: https://github.com/rev-net/revnet-contracts/tree/87a3e811c39e24eda60804c5d725fe5cded0020a
error is Failed to read artifact source file for lib/juice-buyback/lib/juice-contracts-v4/src/enums/JBApprovalStatus.sol:JBApprovalStatus
afaics the relative paths doesn't make a difference for me because i think i'm already using relative paths everywhere
actually i was seeing the error without any imports and simply trying to run a console log in an empty script file
This is a script where I get the error
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
interface IMainFactory {
function test() external;
}
contract Mint2Script is Script {
function run() external {
IMainFactory mainFactory = IMainFactory(0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0); // in anvil
mainFactory.test();
}
}
I run it as forge script Mint2Script --rpc-url http://127.0.0.1:8545 -vvvvv
and get
[⠒] Compiling...
Traces:
[95968] → new Mint2Script@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
└─ ← 258 bytes of code
[23909] Mint2Script::run()
└─ ← EvmError: Revert
Error:
script failed: <no data>
forge 0.2.0 (8343e7d 2024-01-07T00:19:11.564229000Z)
, mac os
P.S. error is thrown only if I do external call of mainFactory.test();
Also seeing this issue, cc @mattsse, same cause and fix described by @thedavidmeister above
A more complex repro can be found here, notice the empty contracts added in DeployConfig.s.sol
and Chains.sol
No fix?
@gakonst @Evalir
has some issue
had similar issue running op-stack deployment scripts. No matching artifact found
revert to an early foundry version fixed it
foundryup -v nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a
I have same issue after founryup.
I reinstalled foundry since I believe I had an outdated version from last year and that did the trick. Just head over to installation on foundry book and reinstall and that should help.
had similar issue running op-stack deployment scripts.
No matching artifact found
revert to an early foundry version fixed itfoundryup -v nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a
this works for me
so an annoyable bug. With no fix from the team.
Any time I get an error with artifacts, the first step I take is forge clean followed by forge build
Hi all, having a cloneable minimal reproduction repo would be greatly appreciated to help narrow this down.
I'm unable to reproduce it with this setup: https://github.com/zerosnacks/foundry-bug-6572-repro I created based on the description of the issue. Any pointers are appreciated @thedavidmeister.
It imports files from https://github.com/zerosnacks/foundry-bug-6572-repro-lib/tree/master/src containing just constants and errors
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