kellpossible/toml-env

Integer Strings Parsed as Float in Environment Variables

開放

#1 建立於 2024年6月21日

 (1 則留言) (0 個反應) (0 位負責人)Rust (2 個分叉)auto 404
buggood first issuehelp wanted

倉庫指標

星標
 (7 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Description: The toml-env library appears to be parsing integer strings into floats, which is not the intended usage. This issue occurs when environment variables are used to override configuration values.

Steps to Reproduce:

  1. Define a configuration with environment variable mapping using the toml-env library.
  2. Set an environment variable with an integer string value.
  3. Run the application.

Example Code:

let config: Option<ConfigFileResponse> = initialize(Args {
    auto_map_env: Some(AutoMapEnvArgs {
        divider: "__",
        prefix: Some("TAGOIO"), // Prefix for environment variables
        transform: Box::new(|name| name.to_lowercase()),
    }),
    // logging: Logging::StdOut,
    config_path: Some(&config_path),
    ..Args::default()
})
.unwrap_or_else(|err| {
    log::error!(target: "error", "Failed to initialize configuration: {}", err);
    std::process::exit(1);
});

Error Message: When running the following command:

TAGOIO__RELAY__DOWNLINK_PORT="1883" cargo run start 

The following error is triggered:

[2024-06-21T19:06:21Z ERROR error] Failed to initialize configuration: Error merging configuration environment variables into config TOML file "./config.toml": Incompatible types at path "$.relay.downlink_port", expected "string" received "float".

Expected Behavior: The environment variable TAGOIO__RELAY__DOWNLINK_PORT should be parsed as an integer string and not converted to a float.

Actual Behavior: The environment variable TAGOIO__RELAY__DOWNLINK_PORT is being parsed as a float, causing a type mismatch error.

Additional Context:

  • toml-env library version: 1.2.0
  • Operating System: macos-sonoma

Proposed Solution: Ensure that integer strings in environment variables are parsed correctly as integers and not converted to floats.

貢獻者指南