Skip to content

feat: warn about missing variables in .env.example - #37

Open
yanshuy wants to merge 3 commits into
aosasona:masterfrom
yanshuy:feat/safe-mode-validation
Open

yanshuy wants to merge 3 commits into
aosasona:masterfrom
yanshuy:feat/safe-mode-validation

Conversation

@yanshuy

@yanshuy yanshuy commented Jun 28, 2026 •

Copy link
Copy Markdown

Related: #9

This PR introduces a validate_template configuration option that warns users if environment variables defined in their template file (defaulting to .env.example) are missing from the loaded environment or OS variables.

Changes included:

  • Added validate_template option to Opts (defaults to True to match the issue's requirements).
  • Added a template_path option to allow users to override the default {path}.example validation file.
  • Added src/dot_env/internal/template.gleam for missing key validation.

Bug Fix: Fixed an issue in src/dot_env_ffi.mjs where get_env for missing keys was incorrectly returning an empty GleamError(Nil) instead of a proper error string (GleamError("key <key> is not set")).

fix: get_env error return for unset variables.
Comment thread src/dot_env/internal/template.gleam Outdated
Comment on lines +7 to +8
conf: List(#(String, String)),
conf_example: List(#(String, String)),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight nit but I try to refrain from the shorter forms like conf, config is preferrable.

Comment thread src/dot_env.gleam Outdated
DotEnv(path: String, debug: Bool, capitalize: Bool, ignore_missing_file: Bool)
DotEnv(
path: String,
check_example: Bool,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this validate_template or similar instead? 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it simple, my current implementation always looks for {path}.example, so check_example made that behavior explicit.
I'm in favor of validate_template, but I think it should come with a template_path option.

@yanshuy

yanshuy commented Jul 20, 2026

Copy link
Copy Markdown
Author

Hi @aosasona
I've pushed a new commit that addresses the feedback!
also updated the pr description

@aosasona

Copy link
Copy Markdown
Owner

Hi @aosasona I've pushed a new commit that addresses the feedback! also updated the pr description

Thank you! I will take a look during the week, it’s been quite busy here today

@aosasona

aosasona commented Jul 21, 2026 •

Copy link
Copy Markdown
Owner

Thanks a lot @yanshuy, great work! Had some time to take a further look and I have some thoughts on what we could do better here, on both ends, and we could much more simplify this I think; I am realizing, we already have all the tools we need, and perhaps a new way to do options and some other things.

I will hack together a prototype this evening and tag you on that, if you want to proceed with the PR, happy to, if not, I can complete it based on that and your existing work while rightfully crediting you.

My thoughts around options is to do this instead:

type Options {
    ValidateTemplates(path: List(String))
    Capitalize
    Debug
    IgnoreMissingFiles
}

so that DotEnv simply takes a List of these options; some performance cost, but DotEnv would be initiated once (hopefully, no one is doing otherwise), and it should be quick enough anyway.

This should make options more composable, and should ideally remove the need to have more and more fields in the Opts type (which is badly named, I hate looking at it right now), there are other larger changes I have in mind that make sense for this breaking update, but are out of scope for this task, I feel less comfortable demanding someone else fix my mistakes.

@yanshuy

yanshuy commented Jul 21, 2026

Copy link
Copy Markdown
Author

I will hack together a prototype this evening and tag you on that, if you want to proceed with the PR, happy to, if not, I can complete it based on that and your existing work while rightfully crediting you.

That would be a great improvement. I'd like to see what you come up with.
Yes, tag me. I'd like to continue working on the PR.
Also I'll push a small commit in the meantime, mostly a naming fix I missed and reverting the tests.

@yanshuy
yanshuy force-pushed the feat/safe-mode-validation branch from 0a9551b to 42ed098 Compare July 21, 2026 10:56
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 this pull request may close these issues.

2 participants