Fix empty .env file handling when isOptional=true#129
Merged
java-james merged 3 commits intomasterfrom Aug 19, 2025
Merged
Conversation
Author
|
@java-james 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: java-james <22756998+java-james@users.noreply.github.com>
Co-authored-by: java-james <22756998+java-james@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Empty .env file throws
Fix empty .env file handling when isOptional=true
Aug 19, 2025
java-james
approved these changes
Aug 19, 2025
Owner
java-james
left a comment
There was a problem hiding this comment.
First time using code pilot to open PRs from issues :)
LGTM
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.
When a
.envfile exists but is empty,DotEnv().load()withisOptional=truewas throwing anEmptyEnvFileError, which is inconsistent with how missing files are handled (they don't throw whenisOptional=true).Problem
The
load()method only caughtFileNotFoundErrorbut notEmptyEnvFileError. When an empty.envfile exists:_getEntriesFromFile()successfully loads the file but finds it emptyEmptyEnvFileErrorload()method doesn't catch this exception, so it propagates up even whenisOptional=trueThis creates inconsistent behavior where:
isOptional=true→ ✅ Works (no exception)isOptional=true→ ❌ ThrowsEmptyEnvFileErrorSolution
Added a catch block for
EmptyEnvFileErrorthat mirrors the exact same logic as the existingFileNotFoundErrorhandler:Now both missing and empty files behave consistently when
isOptional=true- they both setlinesFromFile = []and continue processing normally.Testing
Added comprehensive tests in
test/empty_env_test.dartcovering all scenarios:isOptional=true(should not throw)isOptional=false(should throwEmptyEnvFileError)isOptional=true(should not throw - existing behavior)isOptional=false(should throwFileNotFoundError- existing behavior)Fixes #125.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl-ssl.google.comwget -qO- REDACTED(dns block)curl -fsSL REDACTED(dns block)esm.ubuntu.com/usr/lib/apt/methods/https(dns block)https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.24.5-stable.tar.xzwget -q REDACTED(http block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.