Skip to content

Failing to read env field #74

Description

@djkato

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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