config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Cannot override enum values (other than string) via enviornment variables

Open mbellani opened this issue 4 years ago • 5 comments

Hello, thanks for all the great work on this library. It appears that it's currently not possible to override specific enum variables/values other than string:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: invalid type: string "1", expected usize', src/main.rs:36:58
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Here's a repro of the problem: https://github.com/mbellani/config-error-repro. Apologies in advance if this is something that already works and i just don't know how to use it.

mbellani avatar Mar 01 '21 20:03 mbellani

This issue is most certainly not only with enums, because I'm not certain whether config-rs actually handles if you pass a value for an integer field via ENV.

matthiasbeyer avatar Mar 04 '21 18:03 matthiasbeyer

hello, i'm hitting this same problem as well when trying to use serde to get a struct out of the config; would you be open to a PR that attempts to determine the type of a Value on a best-effort basis inside the impl Source for Environment

blagovestb2c2 avatar Sep 11 '21 21:09 blagovestb2c2

So if you look at the tests in tests/legacy/env.rs, there are examples of how it should work and AFAICS we're running these in CI, don't we? So it should work!

matthiasbeyer avatar Sep 12 '21 17:09 matthiasbeyer

I am running into the same issue. I think the problem is that the tests enable .try_parsing(), which isn't available in any released version of config.

I think it would make sense to release a new version of config.

ctron avatar Feb 18 '22 17:02 ctron

0.12.0 was just released :partying_face: :tada:

matthiasbeyer avatar Feb 19 '22 10:02 matthiasbeyer