Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/pkg/stacks/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ func LoadStackEnv(params Parameters, overload bool) error {
paramsMap := params.ToMap()
for key, value := range paramsMap {
if envValue, ok := currentEnv[key]; ok && envValue != value && !overload {
term.Warnf("The variable %q is set in both the stack and the environment. The value from the environment will be used.\n", key)
if key == "DEFANG_PROVIDER" {
term.Warnf("The variable DEFANG_PROVIDER is set to %q in the environment, but the stack specifies %q. The value from the stack will be used.\n", envValue, value)
} else {
term.Warnf("The variable %q is set to %q in the environment, but the stack specifies %q. The value from the environment will be used.\n", key, envValue, value)
}
}
if _, ok := currentEnv[key]; !ok || overload {
err := os.Setenv(key, value)
Comment on lines 229 to 237
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Warning contradicts behavior for DEFANG_PROVIDER; env is still left untouched.

When overload is false and DEFANG_PROVIDER is already set, the warning says the stack value will be used, but the code path does not call os.Setenv, so downstream code reading os.Getenv("DEFANG_PROVIDER") will still see the environment value. This is exactly the mismatch the PR aims to fix. Consider forcing an override for DEFANG_PROVIDER even when overload is false.

🔧 Proposed fix
-		if _, ok := currentEnv[key]; !ok || overload {
+		shouldOverride := overload || key == "DEFANG_PROVIDER"
+		if _, ok := currentEnv[key]; !ok || shouldOverride {
 			err := os.Setenv(key, value)
 			if err != nil {
 				return fmt.Errorf("could not set env var %q: %w", key, err)
 			}
 		}
🤖 Prompt for AI Agents
In `@src/pkg/stacks/stacks.go` around lines 229 - 237, The warning for
DEFANG_PROVIDER contradicts behavior because when overload is false we currently
warn that the stack value will be used but do not call os.Setenv; change the
logic so DEFANG_PROVIDER is always written into the environment regardless of
overload. Specifically, in the block that checks currentEnv[key], ensure that if
key == "DEFANG_PROVIDER" you call os.Setenv(key, value) (or treat it as if (_,
ok := currentEnv[key]; !ok || overload) is true) so the stack value overrides
the existing env; adjust the term.Warnf message if needed to reflect that
DEFANG_PROVIDER is being forced, and keep references to currentEnv, overload,
os.Setenv, term.Warnf, and the "DEFANG_PROVIDER" constant to locate the code.

Expand Down
Loading