fix: warn when environment variables referenced in config are not set#1628
Open
yosofbadr wants to merge 2 commits into
Open
fix: warn when environment variables referenced in config are not set#1628yosofbadr wants to merge 2 commits into
yosofbadr wants to merge 2 commits into
Conversation
Replace os.ExpandEnv with os.Expand + os.LookupEnv so that a warning is logged whenever an environment variable referenced in the configuration file (including endpoint URLs, headers, and body) is not defined. This helps users diagnose issues where env vars appear to not be interpolated (e.g. due to Docker Compose quoting). Add tests verifying that env var expansion works correctly in endpoint URL, headers, and body fields, and that undefined variables produce the expected empty-string substitution. Closes TwiN#1532
TwiN
reviewed
Apr 18, 2026
| if config == nil { | ||
| t.Fatal("config should not be nil") | ||
| } | ||
| // Undefined env vars should be replaced with empty string |
Owner
There was a problem hiding this comment.
Was this not already the case? Or was it just leaving the unset environment variable as a literal value?
Author
|
Good question @TwiN — yes, empty-string substitution was already the behavior of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
os.ExpandEnvwithos.Expand+os.LookupEnvinparseAndValidateConfigBytesso that a warning is logged whenever an environment variable referenced in the configuration (including endpointurl,headers, andbody) is not defined in the environment.This helps users diagnose issues like the one reported in #1532, where Docker Compose quoting (
- KTOKEN="value") caused the literal quotes to become part of the value, leading to YAML parse errors or unexpected substitution results. The warning makes it immediately clear which variable was not found.Closes #1532
Test plan
TestParseAndValidateConfigBytesWithEnvVarInEndpointURLAndHeaders-- verifies${VAR}in endpoint URL, Authorization header, and body are expandedTestParseAndValidateConfigBytesWithUndefinedEnvVarWarning-- verifies undefined vars expand to empty string (and a warning is logged)TestParseAndValidateConfigBytesWithLiteralDollarSign-- existing test still passes (literal$$handling unchanged)go test ./config/suite passes