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

fix: source parsing for local paths #633

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion ethers-contract/ethers-contract-abigen/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ impl Context {
/// Create a context from the code generation arguments.
pub fn from_abigen(args: Abigen) -> Result<Self> {
// get the actual ABI string
let abi_str = args.abi_source.get().context("failed to get ABI JSON")?;
let abi_str =
args.abi_source.get().map_err(|e| anyhow!("failed to get ABI JSON: {}", e))?;
let mut abi_parser = AbiParser::default();

let (abi, human_readable): (Abi, _) = if let Ok(abi) = abi_parser.parse_str(&abi_str) {
Expand Down
7 changes: 4 additions & 3 deletions ethers-contract/ethers-contract-abigen/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Source {
if matches!(source.chars().next(), Some('[' | '{')) {
return Ok(Source::String(source.to_owned()))
}
let root = env::current_dir()?.canonicalize()?;
let root = env::var("CARGO_MANIFEST_DIR")?;
Source::with_root(root, source)
}

Expand All @@ -72,6 +72,7 @@ impl Source {
P: AsRef<Path>,
S: AsRef<str>,
{
let source = source.as_ref();
let root = root.as_ref();
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
Expand All @@ -87,10 +88,10 @@ impl Source {
.map_err(|_| anyhow!("root path '{}' is not absolute", root.display()))?;
}
}
let url = base.join(source.as_ref())?;
let url = base.join(source)?;

match url.scheme() {
"file" => Ok(Source::local(url.path().to_string())),
"file" => Ok(Source::local(source.to_string())),
"http" | "https" => match url.host_str() {
Some("etherscan.io") => Source::etherscan(
url.path()
Expand Down