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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Behavior with Variable Interpolation in TOML Comments #37

Closed
mre opened this issue Feb 9, 2024 · 0 comments · Fixed by #38
Closed

Unexpected Behavior with Variable Interpolation in TOML Comments #37

mre opened this issue Feb 9, 2024 · 0 comments · Fixed by #38

Comments

@mre
Copy link
Contributor

mre commented Feb 9, 2024

Given the following TOML config:

# key = "${FOO}"

and this main.rs:

use twelf::{config, Layer};

#[config]
struct Conf {}

fn main() {
    Conf::with_layers(&[Layer::Toml("example.toml".into())]).unwrap();
}

When I run the program, I get an error:

thread 'main' panicked at src/main.rs:7:62:
called `Result::unwrap()` on an `Err` value: ShellExpand(LookupError { var_name: "FOO", cause: NotPresent })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It appears that variables within comments are interpolated/expanded.
This is an issue, because I would like to provide a sample config with commented settings which contain environment variables.

mre added a commit to mre/twelf that referenced this issue Feb 9, 2024
Applied the fix to all config files with comment support.

The one downside is, that I had to repeat the same code in each function. That is due to `#[proc_macro]` crate rules: according to Rust's restrictions, these crates can only export items that are procedural macros themselves.

Fixes bnjjj#37
@bnjjj bnjjj closed this as completed in #38 Feb 12, 2024
bnjjj pushed a commit that referenced this issue Feb 12, 2024
Applied the fix to all config files with comment support.

The one downside is, that I had to repeat the same code in each function. That is due to `#[proc_macro]` crate rules: according to Rust's restrictions, these crates can only export items that are procedural macros themselves.

Fixes #37
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

Successfully merging a pull request may close this issue.

1 participant