Skip to content

hh compile fails without detailed error message if /tmp/hardhat-solc is not writable #7161

@KartikSoneji

Description

@KartikSoneji

Version of Hardhat

3.0.0-next.29

What happened?

npx hardhat compile fails with a nondescriptive error message if /tmp/hardhat-solc is not writable.

The spawnCompile() function creates the folder, resulting it being owned by the current user.
If another user attempts compilation while the folder exists, it throws an error.

async function spawnCompile(
command: string,
args: string[],
input: CompilerInput,
): Promise<CompilerOutput> {
// We create a temporary folder to store the output of the compiler in
// We use a random UUID to avoid collisions with other compilations
const tmpFolder = path.join(os.tmpdir(), "hardhat-solc", crypto.randomUUID());
await mkdir(tmpFolder);

mkdir() by default does create folders with mode 777, but since the default umask is 022, it results in a folder with 755
(nodejs/node#15092)
This can be fixed by explicitly using chmod() to set the permission after creation.

Minimal reproduction steps

On a system that has more than one user:

  1. compile project as user a
    sudo su user-a
    npx hardhat compile
  2. switch to user b
    sudo su user-b
  3. attempt to compile project as user b
    $ npx hardhat compile
    Compiling your Solidity contracts...
    Error HHE907: A native version of solc failed to run.
    
    If you are running MacOS, try installing Apple Rosetta.
    
    If this error persists, run "npx hardhat clean --global".

Search terms

compile error, /tmp/hardhat-solc not writable

Metadata

Metadata

Assignees

Labels

type:bugSomething isn't working

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions