Skip to content

Commit

Permalink
Propagate errors loading .env files. (#164)
Browse files Browse the repository at this point in the history
Previously, when requesting `load_dotenv` for a scie, the scie would
silently skip all `.env` file lines after any line with a syntax error.

Fixes #163
  • Loading branch information
jsirois authored Nov 1, 2023
1 parent f44ca18 commit 8a95cdd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 0.13.2

When `load_dotenv` is requested, propagate errors loading any `.env` file found.

## 0.13.1

Support regex removal of env vars with non-utf8 names in commands.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [

[package]
name = "scie-jump"
version = "0.13.1"
version = "0.13.2"
description = "The self contained interpreted executable launcher."
authors = [
"John Sirois <john.sirois@gmail.com>",
Expand Down
9 changes: 9 additions & 0 deletions examples/load/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ echo GET_CONFIG=alt-metadata.json > .env

source .env
grep "${GET_CONFIG}" "${GET_LOG_CONFIG}"

# Motivated by: https://github.com/pantsbuild/scie-pants/issues/307
# shellcheck disable=SC2016 # We with this text to be included verbatim in the .env file.
echo 'PYTHONPATH="/foo/bar:$PYTHONPATH"' >> .env
if ./cowsay "Should fail!"; then
die "The expected .env file loading failure did not happen."
else
log "The expected .env file loading failure was successfully propagated."
fi
4 changes: 2 additions & 2 deletions jump/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jump"
version = "0.13.1"
version = "0.13.2"
description = "The bulk of the scie-jump binary logic."
authors = [
"John Sirois <john.sirois@gmail.com>",
Expand All @@ -21,7 +21,7 @@ itertools = "0.10"
log = { workspace = true }
logging_timer = { workspace = true }
memmap2 = "0.7"
os_str_bytes = "6.5"
os_str_bytes = { version = "6.6", features = ["conversions"] }
regex = { version = "1.9", default-features = false, features = ["std"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
16 changes: 14 additions & 2 deletions jump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,20 @@ pub fn prepare_boot() -> Result<BootAction, String> {

if lift.load_dotenv {
let _timer = timer!(Level::Debug; "jump::load_dotenv");
if let Ok(dotenv_file) = dotenvy::dotenv() {
debug!("Loaded env file from {path}", path = dotenv_file.display());
match dotenvy::dotenv() {
Ok(dotenv_file) => debug!("Loaded env file from {path}", path = dotenv_file.display()),
Err(err) if err.not_found() => {
debug!(
"No .env files found for invocation of {current_exe} from cwd of {cwd:?}",
current_exe = current_exe.exe.display(),
cwd = env::current_dir()
)
}
Err(err) => {
return Err(format!(
"This scie requested .env files be loaded but there was an error doing so: {err}"
))
}
}
}
let payload = &data[jump.size..data.len() - lift.size];
Expand Down

0 comments on commit 8a95cdd

Please sign in to comment.