foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Can't compile project

Open phydy opened this issue 3 years ago • 11 comments

Component

Forge

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

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (084ef3d 2022-09-19T00:07:01.878472846Z)

What command(s) is the bug in?

forge test & forge build

Operating System

Linux

Describe the bug

when I run forge build or forge create I get this error

Failed to create artifact parent folder "/_1/home/phydy/Workprofile/Solidity/XXXX/XXXX/Hyper-Foundry/out/IsolationModeMagic.sol": Permission denied (os error 13)

phydy avatar Sep 19 '22 11:09 phydy

I've got the exact same error too on latest forge :/

JasoonS avatar Sep 19 '22 12:09 JasoonS

yeah, my project worked fine before doing the upgrade

phydy avatar Sep 19 '22 12:09 phydy

this looks like a permission issue when writing the artifact files.

could you check that user has write-access in the project folder?

mattsse avatar Sep 19 '22 13:09 mattsse

I checked the permissions first, but it did not work. apparently the files are generated in the artifacts (/out) but the commad still exits with the same error

phydy avatar Sep 19 '22 13:09 phydy

could you try after

sudo chown -R $(whoami) /_1/home/phydy/Workprofile/Solidity/XXXX/XXXX/Hyper-Foundry

and try after nuking out entirely.

there's also the possibility that running with sudo get's rid of permission issues here

mattsse avatar Sep 19 '22 13:09 mattsse

the issue is that the origin folder /_1/ does not exist.

phydy avatar Sep 19 '22 14:09 phydy

hmm

what does realpath Hyper-Foundry return?

mattsse avatar Sep 19 '22 15:09 mattsse

Seems like upgrading messes the path. I had to create a new project path. Solved the issue.

phydy avatar Sep 20 '22 11:09 phydy

Had the same issue and the solution by @phydy fixed the problem.

I changed the 'out' path variable in foundry.toml to something other than 'out' and the problem resolved. After I did this, I changed it back to 'out' and it now compiles without error.

turbowizardry avatar Sep 21 '22 04:09 turbowizardry

Yeah, nuking the folder and restarting worked for me too (just nuking out didn't do it, had to nuke the parent folder and restore it via git).

JasoonS avatar Sep 21 '22 07:09 JasoonS

interesting, wonder what caused this permission issue...

will add this to trouble shooting section

mattsse avatar Sep 21 '22 14:09 mattsse

i also have this issue

jtguibas avatar Sep 23 '22 18:09 jtguibas

any additional context?

how did you create the project?

did you run anything with sudo?

mattsse avatar Sep 26 '22 15:09 mattsse

no, I first nuked the /out folder, then changed the /out folder name to something else in the .toml file. then ran forge build. it worked. after compiling successfully, I changed back the name to out in the .toml file. Am not sure how this resolved but my suspicions could be about the /_1/ which is not the folder where the home/ directory is as explained in the error /_1/home/phydy/

phydy avatar Sep 27 '22 14:09 phydy

hmm, I wonder if this a path canonicalize issue on UNIX.

what does realpath out print?

mattsse avatar Sep 27 '22 14:09 mattsse

I also get this occasionally on Mac (macOS 12.6) forge 0.2.0 (c2816ca 2022-09-14T00:14:35.602522Z)

I've been running forge test with the --force flag and haven't run into it since, but if I drop the flag it pops back up after a while.

CarterAppleton avatar Sep 30 '22 04:09 CarterAppleton

hmm, this gets weirder.

so somehow this is related to the output dir and its permissions, but this still doesn't make sense since this is also created by forge itself.

if you see this again, I would appreciate it if you could list the folder permissions for both cases

mattsse avatar Sep 30 '22 10:09 mattsse

While running forge test --watch

...
(previous successful test runs)
...

[⠑] Compiling...
[⠘] Compiling 1 files with 0.8.16
[⠃] Compiling 16 files with 0.6.12
[⠰] Compiling 16 files with 0.8.4
[⠢] Solc 0.8.16 finished in 1.45s
[⠰] Solc 0.8.4 finished in 2.21s
[⠃] Solc 0.6.12 finished in 6.46s
Error:
Failed to create artifact parent folder "/_1/Users/carter/dev/goldfinch/mono/packages/protocol/artifacts/Initializable.sol": Read-only file system (os error 30)

foundry.toml

...
out = 'artifacts'
...

Trying to check permissions for the errored folder:

// errored folder
➜ ls -l /_1
ls: /_1: No such file or directory

On successful test runs, I can see forge changing files within

/Users/carter/dev/goldfinch/mono/packages/protocol/artifacts

For your previous question

➜ realpath out
/Users/carter/dev/goldfinch/mono/packages/protocol/out

It seems like forge randomly switches to the _1 prefix, which doesn't exist, and then gets stuck. Once this happens, every subsequent forge test run fails with the same error until I run with forge test --force. After running force once, I can go back to forge test and it runs successfully for a while.


While getting this info I looked into the issue a little more. Foundry's cache solidity-files-cache.json is closer to the root of the issue.

For exactly the same code, the two cases generate a slightly different cache file. I can consistently "repro" by using the bad cache.json and immediately fix by using the good cache.json.

Diffing the two files gives a slightly different header and some different filenames:

Error case: filenames look like ContractName.sol/ContractName.json

Working case: filenames have code version ContractName.sol/ContractName.0.8.5.json (our project is not exclusively 0.8.5 so there are other files like ContractName.sol/ContractName.0.6.12.json)

Example diff:

➜ diff bad.txt good.txt
6876,6877c6876,6877
<       "lastModificationDate": 1664864588608,
<       "contentHash": "7adeaa2ceb83137a3d348a8e7ab36a58",
---
>       "lastModificationDate": 1664864655777,
>       "contentHash": "91c8cc08fde178a6df926326a6abbdcb",
7656c7656
<           "0.6.12+commit.27d51765.Darwin.appleclang": "test.sol/DSTest.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "test.sol/DSTest.0.6.12.json"
7699c7699
<           "0.6.12+commit.27d51765.Darwin.appleclang": "Script.sol/Script.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "Script.sol/Script.0.6.12.json"
7744c7744
<           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/Test.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/Test.0.6.12.json"
7747c7747
<           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/stdError.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/stdError.0.6.12.json"
7750c7750
<           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/stdMath.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/stdMath.0.6.12.json"
7753c7753
<           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/stdStorage.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "Test.sol/stdStorage.0.6.12.json"
7792c7792
<           "0.6.12+commit.27d51765.Darwin.appleclang": "Vm.sol/Vm.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "Vm.sol/Vm.0.6.12.json"
7831c7831
<           "0.6.12+commit.27d51765.Darwin.appleclang": "console.sol/console.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "console.sol/console.0.6.12.json"
7870c7870
<           "0.6.12+commit.27d51765.Darwin.appleclang": "console2.sol/console2.json"
---
>           "0.6.12+commit.27d51765.Darwin.appleclang": "console2.sol/console2.0.6.12.json"
9819c9819
<           "0.8.16+commit.07a7930e.Darwin.appleclang": "IERC721EnumerableUpgradeable.sol/IERC721EnumerableUpgradeable.json"
---
>           "0.8.16+commit.07a7930e.Darwin.appleclang": "interfaces/IERC721EnumerableUpgradeable.sol/IERC721EnumerableUpgradeable.json"
9861c9861
<           "0.8.16+commit.07a7930e.Darwin.appleclang": "IERC721Upgradeable.sol/IERC721Upgradeable.json"
---
>           "0.8.16+commit.07a7930e.Darwin.appleclang": "interfaces/IERC721Upgradeable.sol/IERC721Upgradeable.json"
9900c9900
<           "0.8.16+commit.07a7930e.Darwin.appleclang": "Initializable.sol/Initializable.json"
---
>           "0.8.4+commit.c7e474f2.Darwin.appleclang": "Initializable.sol/Initializable.0.8.4.json"
10492c10492
<           "0.8.16+commit.07a7930e.Darwin.appleclang": "ContextUpgradeable.sol/ContextUpgradeable.json"
---
>           "0.8.4+commit.c7e474f2.Darwin.appleclang": "ContextUpgradeable.sol/ContextUpgradeable.0.8.4.json"
10690c10690
<           "0.8.16+commit.07a7930e.Darwin.appleclang": "IERC165Upgradeable.sol/IERC165Upgradeable.json"
---
>           "0.8.4+commit.c7e474f2.Darwin.appleclang": "IERC165Upgradeable.sol/IERC165Upgradeable.0.8.4.json"

CarterAppleton avatar Oct 04 '22 06:10 CarterAppleton

thanks for this, could you please add a bad cache.json?

still no idea why realpath would add a /_1 prefix...

mattsse avatar Oct 05 '22 10:10 mattsse

Randomly got the error when running forge script. Running forge build --force fixed the issue for me as well.

penandlim avatar Oct 06 '22 00:10 penandlim

it would be helpful if you could share all the logs you get when running with RUST_LOG=ethers,ethers_solc,forge forge test for a bad run @CarterAppleton

mattsse avatar Oct 07 '22 16:10 mattsse

Should be fixed in #1772

gakonst avatar Oct 07 '22 17:10 gakonst

the potential fix will ship in next nightly,

if you still see this please ping to reopen.

mattsse avatar Oct 07 '22 17:10 mattsse

okay, I finally found the bug -.-

sorry it took so long, there is a bug with how we adjust output paths if there are duplicate contracts.

fixing rn.

mattsse avatar Oct 13 '22 15:10 mattsse

why do i get this error when i try to compile ?

Error (6275): Source "forge-std/Test.sol" not found: File not found. Searched the following location

seerether avatar Jul 09 '23 10:07 seerether