Skip to content

Commit

Permalink
fix(cheatcodes): env error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 10, 2023
1 parent 03f6026 commit d016aa4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions crates/cheatcodes/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ fn map_env_err<'a>(key: &'a str, value: &'a str) -> impl FnOnce(Error) -> Error
// <value>
// ^
// expected at least one digit
Error::from(e.to_string().replace(value, &format!("${key}")))
let mut e = e.to_string();
e = e.replacen(&format!("\"{value}\""), &format!("${key}"), 1);
e = e.replacen(&format!("\n{value}\n"), &format!("\n${key}\n"), 1);
Error::from(e)
}
}

Expand All @@ -282,11 +285,10 @@ mod tests {
#[test]
fn parse_env_uint() {
let key = "parse_env_uint";
let value = "123xyz";
let value = "t";
env::set_var(key, value);

let err = env(key, &DynSolType::Uint(256)).unwrap_err().to_string();
assert!(!err.contains(value));
assert_eq!(err.matches("$parse_env_uint").count(), 2, "{err:?}");
env::remove_var(key);
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/repros/Issue6070.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract Issue6066Test is DSTest {
function testNonPrefixed() public {
vm.setEnv("__FOUNDRY_ISSUE_6066", "abcd");
vm.expectRevert(
"failed parsing \"$__FOUNDRY_ISSUE_6066\" as type `uint256`: missing hex prefix (\"0x\") for hex string"
"failed parsing $__FOUNDRY_ISSUE_6066 as type `uint256`: missing hex prefix (\"0x\") for hex string"
);
uint256 x = vm.envUint("__FOUNDRY_ISSUE_6066");
}
Expand Down

0 comments on commit d016aa4

Please sign in to comment.