fix: don't print a stderr warning when .env simply doesn't exist - #181
Merged
Merged
Conversation
godotenv.Load() returns an error whenever .env is absent, which is the normal case for setups that use shell env vars or CI secrets instead of a checked-in .env file. Only warn when .env exists but fails to parse. Closes #178 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The missing .env test should assert that stderr is exactly empty.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Suppresses warnings for missing .env files while retaining malformed-file diagnostics.
Changes:
- Ignore
os.IsNotExisterrors fromgodotenv.Load. - Add end-to-end tests for missing and malformed
.envfiles.
File summaries
| File | Description |
|---|---|
internal/cli/cli.go |
Filters expected missing-file errors. |
internal/cli/cli_test.go |
Covers missing and malformed .env behavior. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Per Copilot review on #181: a stricter empty-stderr check is more precise than substring-checking for ".env", since the code path under test doesn't write anything else to stderr. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…tenv-warning # Conflicts: # internal/cli/cli_test.go
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
internal/cli.Executeno longer printsfailed to load .env: open .env: no such file or directoryon every run when there's simply no.envfile (the common case for shell-env and CI-secret setups)..envfile that exists but fails to parse still produces the same clear warning on stderr.Changes
godotenv.Load()'s error when it's not anos.IsNotExisterror.TestExecute_MissingDotEnv_NoStderrWarningandTestExecute_MalformedDotEnv_PrintsStderrWarning, covering both cases end-to-end throughExecute.Testing
go build ./...,go vet ./..., andgo test ./...all pass.golangci-lint runpanics in this local environment on bothmainand this branch (pre-existing Go 1.27 vs. golangci-lint toolchain incompatibility, confirmed unrelated to this change) — CI's pinned toolchain should be unaffected, but flagging in case it needs a separate look.gofmtis clean on the touched files (once CRLF is stripped, which is a known false-positive on this Windows checkout, per repo convention).Closes #178
🤖 Generated with Claude Code