allan2 / dotenvy

A well-maintained fork of the dotenv crate
MIT License
664 stars 40 forks source link

Better default error for `var(...)` #14

Open clifton opened 2 years ago

clifton commented 2 years ago
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: EnvVar(NotPresent)'

I was looking into mapping the error and adding context (eg, "missing VAR_XYZ"), but it would be a breaking API change. Any suggestions for how to structure that change?

allan2 commented 1 year ago

This is a great idea that is definitely worth implementing. I opened a discussion (#25) for this.

Maybe something like this?

// dotenvy::Error
enum Error {
    LineParse(String, usize),
    Io(Error),
    EnvVar(VarError, String),  // name is here
}

This is just a suggestion. It could be possible that the name information could be used for other variants like LineParse, I am not sure yet.

clifton commented 1 year ago

Great, thanks