Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
thedavidmeister opened this issue Dec 11, 2023 · 27 comments
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug T-to-reproduce Type: requires reproduction
Milestone

Comments

@thedavidmeister
Copy link

thedavidmeister commented Dec 11, 2023

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

@thedavidmeister thedavidmeister added the T-bug Type: bug label Dec 11, 2023
@Alec1017
Copy link

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

@Alec1017
Copy link

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
Copy link

mejango commented Dec 17, 2023

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
Copy link
Author

thedavidmeister commented Dec 17, 2023

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
Copy link

crystalbit commented Jan 8, 2024

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
Copy link
Collaborator

mds1 commented Jan 12, 2024

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
Copy link

No fix?

@gakonst @Evalir

@script-money
Copy link

has some issue

@alfredo-stonk
Copy link

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
Copy link

havi-kim commented Apr 6, 2024

I have same issue after founryup.

@danieliniguezv
Copy link

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
Copy link

coffiasd commented Jun 4, 2024

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

@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-script Command: forge script T-to-investigate Type: to investigate labels Jun 27, 2024
@hungtran2492
Copy link

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

@viveknath13
Copy link

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

@zerosnacks zerosnacks changed the title failed to read artifact source when running forge script with lib dependencies that include files without a matching contract name bug: failed to read artifact source when running forge script with lib dependencies that include files without a matching contract name Jul 5, 2024
@zerosnacks zerosnacks added T-to-reproduce Type: requires reproduction and removed T-to-investigate Type: to investigate labels Jul 5, 2024
@zerosnacks
Copy link
Member

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 zerosnacks changed the title bug: failed to read artifact source when running forge script with lib dependencies that include files without a matching contract name bug(forge script): failed to read artifact source with lib dependencies that include files without a matching contract name Jul 5, 2024
@ismailmoazami
Copy link

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

@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@KPR-V
Copy link

KPR-V commented Aug 21, 2024

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

@KPR-V
Copy link

KPR-V commented Aug 21, 2024

using

forge clean 

worked for me

@Joyosmit
Copy link

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
Copy link

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
Copy link

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

forge clean

See forge-clean.

@zhiqiangxu
Copy link
Contributor

zhiqiangxu commented Sep 25, 2024

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)

@justefg
Copy link

justefg commented Oct 9, 2024

i can confirm forge clean didn't work for me either with 0.2.0. unfortunately, i cannot give a minimal reproducible example. adding EmptyContract like the author suggest didn't help either. this such a bummer as i'll probably need to use another tool for testing and deployment.

@Neddie28
Copy link

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

This worked for me. thanks a lot🙏

@grandizzy
Copy link
Collaborator

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

@zhiqiangxu
Copy link
Contributor

@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.

@grandizzy
Copy link
Collaborator

we're going to close this optimistically as were not able to reproduce it and looks like forge clean eventually solves it for all mentioned cases. Please open new ticket with details to reproduce if still occurs. Thank you!

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug T-to-reproduce Type: requires reproduction
Projects
Status: Done
Development

No branches or pull requests