Skip to content

Commit

Permalink
Merge pull request #132 from augustoccesar/fix/required-check
Browse files Browse the repository at this point in the history
fix: correct check for required attribute
  • Loading branch information
allan2 authored Oct 5, 2024
2 parents db0d6aa + 474d974 commit d697971
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dotenvy-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ pub fn load(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut loader = EnvLoader::with_path(#path).sequence(seq);
if let Err(e) = unsafe { loader.load_and_modify() } {
if let Some(io_err) = e.source().and_then(|src| src.downcast_ref::<io::Error>()) {
if io_err.kind() == io::ErrorKind::NotFound && !#required {
// `required` is false and file not found, so continue
match (io_err.kind(), #required) {
(io::ErrorKind::NotFound, false) => (),
_ => {
eprintln!("Failed to load env file from path '{}': {e}", #path);
process::exit(1);
}
}
}
eprintln!("Failed to load env file from path '{}': {e}", #path);
process::exit(1);

}
};

Expand Down

0 comments on commit d697971

Please sign in to comment.