foundry icon indicating copy to clipboard operation
foundry copied to clipboard

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

Open thedavidmeister opened this issue 1 year ago • 24 comments

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

thedavidmeister avatar Dec 11 '23 18:12 thedavidmeister

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

Alec1017 avatar Dec 14 '23 17:12 Alec1017

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?

Alec1017 avatar Dec 14 '23 17:12 Alec1017

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

mejango avatar Dec 17 '23 00:12 mejango

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

thedavidmeister avatar Dec 17 '23 06:12 thedavidmeister

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

crystalbit avatar Jan 08 '24 00:01 crystalbit

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

mds1 avatar Jan 12 '24 18:01 mds1

No fix?

@gakonst @Evalir

0xTimepunk avatar Feb 14 '24 19:02 0xTimepunk

has some issue

script-money avatar Mar 16 '24 14:03 script-money

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

alfredo-stonk avatar Apr 05 '24 18:04 alfredo-stonk

I have same issue after founryup.

havi-kim avatar Apr 06 '24 08:04 havi-kim

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.

danieliniguezv avatar Apr 23 '24 06:04 danieliniguezv

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

coffiasd avatar Jun 04 '24 08:06 coffiasd

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

hungtran2492 avatar Jul 01 '24 11:07 hungtran2492

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

viveknath13 avatar Jul 03 '24 05:07 viveknath13

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

zerosnacks avatar Jul 05 '24 12:07 zerosnacks

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

ismailmoazami avatar Jul 16 '24 12:07 ismailmoazami