Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

ethers-solc version parsing fails with newline suffix #2004

Closed
elizabethdinella opened this issue Jan 3, 2023 · 0 comments · Fixed by #2005
Closed

ethers-solc version parsing fails with newline suffix #2004

elizabethdinella opened this issue Jan 3, 2023 · 0 comments · Fixed by #2005
Labels
bug Something isn't working

Comments

@elizabethdinella
Copy link
Contributor

elizabethdinella commented Jan 3, 2023

Version
ethers-solc v1.0.2

Platform
Linux ash11 4.15.0-143-generic #147-Ubuntu SMP Wed Apr 14 16:10:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Description
Using solc installed from solc-select the version cannot be parsed.

When parsing the solc version I get the error: SemverError(Error("unexpected end of input while parsing major version number"))

Running solc --version I get:

solc, the solidity compiler commandline interface
Version: 0.8.12+commit.f00d7308.Linux.g++


After some debugging of this code:
https://github.com/gakonst/ethers-rs/blob/master/ethers-solc/src/compile/mod.rs#L684-L697

I found that solc --version output includes two trailing newlines:

[src/compile/mod.rs:687] &output = Output {
  status: ExitStatus(
    unix_wait_status(
      0,
    ),
  ),
  stdout: "solc, the solidity compiler commandline interface\nVersion: 0.8.12+commit.f00d7308.Linux.g++\n\n",
  stderr: "",
}
[src/compile/mod.rs:689] output.stdout.lines().last() = Some(
  Ok(
    "",
  ),
)

The last() call evaluates to an empty string causing the version parsing to fail.

I fixed locally by stripping newlines as follows:

fn version_from_output(output: Output) -> Result<Version> {
    if output.status.success() {
        let version =
            output.
            stdout.
            lines().
            **filter(|l| !l.as_ref().unwrap().is_empty()).**
            last()
            .ok_or_else(|| SolcError::solc("version not found in solc output"))?
            .map_err(|err| SolcError::msg(format!("Failed to read output: {err}")))?;
        // NOTE: semver doesn't like `+` in g++ in build metadata which is invalid semver
        //dbg!(&version);
        Ok(Version::from_str(&version.trim_start_matches("Version: ").replace(".g++", ".gcc"))?)
    } else {
        Err(SolcError::solc(String::from_utf8_lossy(&output.stderr).to_string()))
    }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant