Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue parsing for more missing required values #45

Open
hbobenicio opened this issue Aug 16, 2019 · 4 comments
Open

Continue parsing for more missing required values #45

hbobenicio opened this issue Aug 16, 2019 · 4 comments

Comments

@hbobenicio
Copy link

hbobenicio commented Aug 16, 2019

馃挕 Feature description

Continue parsing for more missing required values (instead stopping at the first one).

馃槏 Motivation

This can provide more information to the user/devops/developer in order to setup all missing values at once (instead of one by one).

馃捇 Basic example

Today, this:

use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct Config {
    host: String,
    port: String,
}

fn main() {
    match envy::prefixed("APP_").from_env::<Config>() {
        Ok(config) => println!("{:#?}", config),
        Err(err) => {
            eprintln!("error: {:#?}", err);
            std::process::exit(1);
        }
    }
}

running with:

cargo run

outputs this:

error: MissingValue(
    "host",
)

The desired behaviour would output this instead:

error: MissingValues(
    [
        "host", // Or even better: "APP_HOST", considering prefix
        "port" // Or even better: "APP_PORT", considering prefix
    ]
)
@softprops
Copy link
Owner

Oh that's interesting. This crate relies heavily on serde and I'm not sure that serde provides that hook but I can do some investigation.

@hbobenicio
Copy link
Author

@softprops Any progress?

That would be super handy! :)

@hbobenicio
Copy link
Author

hbobenicio commented Dec 4, 2019

Is it possible to create a custom serde deserializer that, when trying to deserialize a given struct property, checks for failure then save an error context (like a "names of the missing required fields" vector) and then continue the deserialization process somehow ? (for the other missing required fields)

When I mean "required" here is some deserializable type that is not an Option<T> (which is ok already)

@hbobenicio
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants