Skip to content

Fix/dotenv malformed line warning#275

Closed
spartan124 wants to merge 3 commits into
Grainlify:mainfrom
spartan124:fix/dotenv-malformed-line-warning
Closed

Fix/dotenv malformed line warning#275
spartan124 wants to merge 3 commits into
Grainlify:mainfrom
spartan124:fix/dotenv-malformed-line-warning

Conversation

@spartan124

@spartan124 spartan124 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #172

This PR addresses the issue where `godotenv.Load()` would silently skip malformed lines (e.g.

missing =, stray quotes) without any warning, causing variables to be silently unset rather
than failing fast.

Instead of swallowing the parsing errors during local development, we now capture the errors 

returned by godotenv.Load() and emit clear warnings via log.Printf. This gives the
developer immediate visibility into malformed .env files, preventing confusing downstream
errors in config validation.

## Changes Made                                                                              
                                                                                             
- **Updated `internal/config/dotenv.go`**: Captured parsing errors from `godotenv.Load()` to 

surface loud warnings to stdout/logger instead of silently discarding them.
- Added Edge-Case Tests (internal/config/dotenv_test.go): Covered all specified edge
cases: missing equals sign, unterminated quotes, duplicate keys (last-wins behavior), comment-
only files, empty files, and Windows line endings (CRLF).
- Boosted Coverage (internal/config/config_helpers_test.go): Added extensive tests for
config.go environment helpers, pushing the overall test coverage for the internal/config
package to 99.2% (well beyond the 95% requirement).

## Acceptance Criteria Met

- [x] Malformed lines produce a visible warning instead of silent omission.
- [x] Valid `.env` files parse identically to before.
- [x] Duplicate-key behavior is explicit and tested.
- [x] Minimum 95% test coverage achieved (currently at 99.2%).

## Security Notes

As required, this change preserves security invariants. The `dotenv.go` loader remains best- 

effort for local development. By capturing and logging godotenv failures rather than trying
to partially patch/parse the environment files manually, we avoid the risk of fallback default
overrides or security loopholes for critical tokens (like JWT_SECRET).

@spartan124 spartan124 closed this Jul 25, 2026
@spartan124
spartan124 deleted the fix/dotenv-malformed-line-warning branch July 25, 2026 19:31
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.

Reject malformed lines instead of silently skipping in internal/config/dotenv.go

1 participant