Skip to content

Commit

Permalink
Don't fail with --env and nonexistent env vars (#8039)
Browse files Browse the repository at this point in the history
Instead just leave it unset in the guest.
  • Loading branch information
alexcrichton authored Mar 2, 2024
1 parent 7565cef commit 0f7b175
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,15 @@ impl RunCommand {
for (key, value) in self.vars.iter() {
let value = match value {
Some(value) => value.clone(),
None => std::env::var(key)
.map_err(|_| anyhow!("environment variable `{key}` not found"))?,
None => match std::env::var_os(key) {
Some(val) => val
.into_string()
.map_err(|_| anyhow!("environment variable `{key}` not valid utf-8"))?,
None => {
// leave the env var un-set in the guest
continue;
}
},
};
builder.env(key, &value)?;
}
Expand Down Expand Up @@ -775,8 +782,15 @@ impl RunCommand {
for (key, value) in self.vars.iter() {
let value = match value {
Some(value) => value.clone(),
None => std::env::var(key)
.map_err(|_| anyhow!("environment variable `{key}` not found"))?,
None => match std::env::var_os(key) {
Some(val) => val
.into_string()
.map_err(|_| anyhow!("environment variable `{key}` not valid utf-8"))?,
None => {
// leave the env var un-set in the guest
continue;
}
},
};
builder.env(key, &value);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ fn specify_env() -> Result<()> {
"tests/all/cli_tests/print_env.wat",
])
.output()?;
assert!(!output.status.success());
assert!(output.status.success());

Ok(())
}
Expand Down

0 comments on commit 0f7b175

Please sign in to comment.