Skip to content

fix(run): surface --env-from-file parse errors instead of dropping the environment - #14244

Open
htoyoda18 wants to merge 1 commit into
docker:mainfrom
htoyoda18:fix/run-env-from-file-error-swallowed
Open

htoyoda18 wants to merge 1 commit into
docker:mainfrom
htoyoda18:fix/run-env-from-file-error-swallowed

Conversation

@htoyoda18

Copy link
Copy Markdown
Contributor

What I did
getEnvironment in cmd/compose/run.go silently returned (nil, nil) whenever
dotenv.ParseWithLookup failed to parse an --env-from-file (e.g. a
required-variable reference like ${VAR:?message} that can't resolve). Because
the error was swallowed, runRun treated the call as successful and the
container started with an empty environment — including variables passed
via -e
— with no error shown to the user.

This PR:

  • returns the parse error (wrapped with the file name) instead of discarding it
  • closes the file handle opened by os.Open, which was previously never closed
  • adds cmd/compose/run_test.go (no unit tests existed for run.go before), covering: e/-env-from-file merge precedence, a missing file, and a malformed file — the last case reproduces the original bug and would have failed before this fix

No behavior change for the success path; only the error path changes from
"silently continue with an empty environment" to "return an error".

Related issue

N/A

(not mandatory) A picture of a cute animal, if possible in relation to what you did
🐈🐈🐈

…e environment

Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
@htoyoda18
htoyoda18 requested review from a team as code owners September 19, 2026 23:43
@htoyoda18
htoyoda18 requested review from glours and ndeloof September 19, 2026 23:43
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.

1 participant