feat: fail fast when no monitoring targets configured #75
Reference in New Issue
Block a user
Delete Branch "fix/issue-69-empty-targets-validation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
When
DNSWATCHER_TARGETSis empty (the default), dnswatcher previously started successfully and ran indefinitely monitoring nothing. This is a common misconfiguration — forgetting to set the variable or making a typo in its name — and gave no indication anything was wrong.Changes
ErrNoTargetssentinel error ininternal/config/config.goparseAndValidateTargets()helper to validate that at least one domain or hostname is configured after target classification"no monitoring targets configured: set DNSWATCHER_TARGETS environment variable"DNSWATCHER_TARGETSis required and dnswatcher will refuse to start without itHow it works
The validation runs during config construction (via uber/fx), before the watcher or any other component starts. If
DNSWATCHER_TARGETSis empty or contains only whitespace/empty entries,buildConfig()returnsErrNoTargets, which causes fx to fail startup with a clear error message.This is fail-fast behavior: a monitoring daemon with nothing to monitor is a misconfiguration and should not silently run.
Closes #69
Review: ✅ PASS
Summary
Clean, minimal implementation of fail-fast validation when
DNSWATCHER_TARGETSis empty. Correctly addresses issue #69.Code Review
internal/config/config.go(+26/-4)ErrNoTargetssentinel error: exported, descriptive message, good practice ✅parseAndValidateTargets()helper: cleanly extracted frombuildConfig(), preserves the existingClassifyTargetserror wrapping, addslen(domains) == 0 && len(hostnames) == 0check ✅parseCSV()before reaching validation ✅README.md(+6/-0)DNSWATCHER_TARGETSis required and dnswatcher will refuse to start without it ✅Verification
docker build .— PASS (all tests green)Notes
parseAndValidateTargets(), but acceptable: it is unexported, the validation is a trivial length check, andClassifyTargetsis already well-tested inclassify_test.go.TestQueryNameserver_TXT(live DNS — google.com TXT returned empty from one nameserver). Unrelated to this PR; passed on retry. Pre-existing issue tracked separately.