Skip to content

Proposal: improve error descriptions (capitalize variables and respect prefix) #67

@tomkarw

Description

@tomkarw

Hey @softprops,
I encountered the problem of error accuracy when working with envy.

This issue seems vaguely relevant, but it's missing any description, so I decided to create a new one.

The problem

Basically given code like this

struct Env {
    pub some_var: String
}

fn main() {
    let _env = envy::prefixed("ABC_")
        .from_env::<Env>().unwrap();
}

I'm getting an error like this:

MissingValue("some_var")

where I'd like to see an error like this:

MissingValue("ABC_SOME_VAR")

Quick solution

I was able to overcome this in my project by a quick hack:

panic!("Missing value: ABC_{}", err.to_string().split_whitespace().last().unwrap().to_uppercase());

but obviously it would be better if envy just had nicer errors in the first place.

Proposal

I would be happy to introduce a PR, improving the error messages and adjusting the behavior for prefixed variables. Let me know if you're interested in seeing this, is the proposed improvement acceptable, and I'll work on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions