foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.14k stars 1.69k forks source link

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

Open thedavidmeister opened 9 months ago

thedavidmeister commented 9 months ago

Component

Forge

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

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

Alec1017 commented 9 months ago

+1 on this. Also receiving the same error. Using forge 0.2.0 as well

Alec1017 commented 9 months ago

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?

mejango commented 9 months ago

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

thedavidmeister commented 9 months ago

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

crystalbit commented 8 months ago

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();

mds1 commented 8 months ago

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

0xTimepunk commented 7 months ago

No fix?

@gakonst @Evalir

script-money commented 6 months ago

has some issue

alfredo-stonk commented 5 months ago

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

havi-kim commented 5 months ago

I have same issue after founryup.

danieliniguezv commented 5 months ago

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.

coffiasd commented 3 months ago

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

this works for me

hungtran2492 commented 2 months ago

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

viveknath13 commented 2 months ago

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

zerosnacks commented 2 months ago

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

ismailmoazami commented 2 months ago

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

KPR-V commented 1 month ago

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

KPR-V commented 1 month ago

using

forge clean 

worked for me

Joyosmit commented 3 weeks ago

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

Did this and it fixed it for me. Reinstalling foundry didnt

FredrikCarlssn commented 3 weeks ago

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

henriquemenegaz commented 2 weeks ago

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

forge clean

See forge-clean.