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

fix: handle non existing Cargo.toml edge case #1886

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ethers-contract/ethers-contract-abigen/src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,17 @@ impl MultiBindingsInner {

/// parses the active Cargo.toml to get what version of ethers we are using
fn find_crate_version(&self) -> Result<String> {
let cargo_dir = std::env::current_dir()?.join("Cargo.toml");
let data = std::fs::read_to_string(cargo_dir)?;
let cargo_toml = std::env::current_dir()?.join("Cargo.toml");

let default_dep = || {
"ethers = {{ git = \"https://github.com/gakonst/ethers-rs\", default-features = false, features = [\"abigen\"] }}".to_string()
};

if !cargo_toml.exists() {
return Ok(default_dep())
}

let data = fs::read_to_string(cargo_toml)?;
let toml = data.parse::<Value>()?;

let ethers = toml
Expand All @@ -588,7 +597,7 @@ impl MultiBindingsInner {
version
))
} else {
Ok("ethers = {{ git = \"https://github.com/gakonst/ethers-rs\", default-features = false, features = [\"abigen\"] }}".to_string())
Ok(default_dep())
}
}

Expand Down