envy icon indicating copy to clipboard operation
envy copied to clipboard

Failing to read env field

Open djkato opened this issue 2 years ago • 2 comments

According to #65 env files should work with combination from dotenvy, but they don't seem to for me.

env file: .env

REQUIRED_SALEOR_VERSION=">=3.11.7<4"
SALEOR_APP_ID="dummy-saleor-app-rs"
APP_API_BASE_URL="http://localhost:8000/graphql/"
APL="redis"
APL_URL="redis://redis:6379/2"
LOG_LEVEL="DEBUG"

running: config.rs


use crate::saleor::AplType;
use tracing::Level;

#[derive(Debug, Deserialize)]
#[serde(remote = "Level")]
pub enum LocalTracingLevel {
    TRACE,
    DEBUG,
    INFO,
    WARN,
    ERROR,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct Config {
    pub required_saleor_version: String,
    pub saleor_app_id: String,
    pub app_api_base_url: String,
    pub apl: AplType,
    pub apl_url: String,
    #[serde(with = "LocalTracingLevel")]
    pub log_level: tracing::Level,
}

impl Config {
    pub fn load() -> Result<Self, envy::Error> {
        dotenvy::dotenv().unwrap();

        for (key, value) in std::env::vars() {
            println!("{key}: {value}");
        }
        let env = envy::from_env::<Config>();
        dbg!(&env);
        env
    }
}

Error/stdout:

REQUIRED_SALEOR_VERSION: >=3.11.7<4
SALEOR_APP_ID: dummy-saleor-app-rs
APP_API_BASE_URL: http://localhost:8000/graphql/
APL: redis
APL_URL: redis://redis:6379/2
LOG_LEVEL: DEBUG
[src/config.rs:36:9] &env = Err(
    MissingValue(
        "REQUIRED_SALEOR_VERSION",
    ),
)
Error: missing value for field REQUIRED_SALEOR_VERSION

djkato avatar Feb 16 '24 20:02 djkato

#[serde(rename_all = "SCREAMING_SNAKE_CASE")]

This seems to have been the culprit.

djkato avatar Feb 16 '24 20:02 djkato