Skip to content

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

Description

@Jagadeeshftw

📌 Description

internal/config/dotenv.go (51 lines) parses .env files for local/dev config loading. If it currently skips malformed lines (e.g. missing =, stray quotes) without any warning, a typo in an env var silently results in that variable being unset rather than failing fast — which then surfaces as a confusing downstream error in internal/config/config.go.

🧩 Requirements and context

  • Inspect current parsing behavior for malformed lines and decide fail-fast vs warn-and-skip (recommend: warn loudly via stderr/logger, since this only affects local dev).
  • Add a test for common malformation cases: missing =, unterminated quote, duplicate key, comment-only line, empty file.
  • Ensure the existing valid-parsing behavior is unchanged.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b fix/dotenv-malformed-line-warning

2. Implement changes

  • Modify: internal/config/dotenv.go — add malformed-line detection and a clear warning log.
  • Add test: internal/config/config_test.go (or a new dotenv_test.go) covering the malformation cases.

3. Test and commit

  • Run tests:
go test ./internal/config/... -v
  • Cover edge cases: missing equals sign, unterminated quote, duplicate key (last-wins vs first-wins), Windows line endings (CRLF).
  • Include test output and details in the PR description.

Example commit message

fix: warn on malformed .env lines instead of silently skipping them

✅ Acceptance criteria

  • Malformed lines produce a visible warning instead of silent omission.
  • Valid .env files parse identically to before.
  • Duplicate-key behavior is explicit and tested.

🔒 Security notes

Low direct security impact (dev-only tooling), but a silently-dropped JWT_SECRET or similar could lead to a weak/default value being used unnoticed — validate no sensitive default is used as a fallback.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebackendBackend / API workbugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions