Add fail-fast Validate() checks to EmailVerification, PasswordReset, and APIKey handlers#340
Merged
Merged
Conversation
Copilot created this pull request from a session on behalf of
veverkap
May 23, 2026 19:45
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds fail-fast startup validation to three HTTP handlers in handler/ (EmailVerification, PasswordReset, APIKey) so missing required dependencies are detected at server initialization rather than during the first live request.
Changes:
- Added
Validate() errortoEmailVerificationHandler,PasswordResetHandler, andAPIKeyHandlerto assert required dependencies are non-nil. - Added focused unit tests to cover the new validation behavior for each handler.
Show a summary per file
| File | Description |
|---|---|
| handler/password_reset.go | Adds PasswordResetHandler.Validate() to fail fast when Users/Resets are nil. |
| handler/password_reset_test.go | Adds tests for password-reset handler validation success/failure cases. |
| handler/email_verification.go | Adds EmailVerificationHandler.Validate() to fail fast when Users/Verifications are nil. |
| handler/email_verification_test.go | Adds tests for email-verification handler validation success/failure cases. |
| handler/apikey.go | Adds APIKeyHandler.Validate() to fail fast when APIKeys/URLParamFunc are nil. |
| handler/apikey_test.go | Adds tests for API key handler validation success/failure cases. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 1
- EmailVerificationHandler.Validate() now checks SendEmail is set - PasswordResetHandler.Validate() now checks SendResetEmail is set - APIKeyHandler.Delete() returns 500 when URLParamFunc is nil instead of panicking - Add tests for all three new validation/guard paths
This was referenced May 23, 2026
github-actions Bot
added a commit
that referenced
this pull request
May 23, 2026
…n, and PasswordReset handlers Add Validate() call examples and descriptions to the Configuration sections of api-keys.md, email-verification.md, and password-reset.md, matching the existing pattern in magic-links.md and totp.md. Triggered by #340 which added Validate() to these three handlers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
veverkap
added a commit
that referenced
this pull request
May 23, 2026
* docs: document Validate() startup checks for APIKey, EmailVerification, and PasswordReset handlers Add Validate() call examples and descriptions to the Configuration sections of api-keys.md, email-verification.md, and password-reset.md, matching the existing pattern in magic-links.md and totp.md. Triggered by #340 which added Validate() to these three handlers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(handler): fix contradictory Validate() field lists and remove duplicate code blocks email-verification.md and password-reset.md each had two descriptions of Validate() that disagreed on which fields are required. The inline note omitted SendEmail/SendResetEmail, the secondary paragraph was correct but included a duplicate code block. Consolidate into a single accurate description listing all three required fields with the descriptive error message format. --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Patrick Veverka <veverkap@users.noreply.github.com>
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.
Three handlers in
handler/were missing startup validation while peer handlers already enforce config checks. This left nil dependencies undetected until first live request, including a nil function-pointer panic path inAPIKeyHandler.Delete.Validation parity across handlers
Validate() errorto:EmailVerificationHandler(Users,Verificationsrequired)PasswordResetHandler(Users,Resetsrequired)APIKeyHandler(APIKeys,URLParamFuncrequired)Panic-path removal for API key deletion
APIKeyHandlernow rejects missingURLParamFuncat startup viaValidate()instead of failing at runtime on first delete call.Targeted unit coverage
Greptile Summary
This PR adds
Validate()startup checks to three previously unprotected handlers (EmailVerificationHandler,PasswordResetHandler,APIKeyHandler), bringing them in line with peer handlers likeMagicLinkHandler. It also adds a belt-and-suspenders nil guard insideAPIKeyHandler.Delete()to prevent a runtime panic if the handler is used without first callingValidate().Validate()parity: All three handlers now check every required dependency — includingSendEmailandSendResetEmail, which the struct comments already documented as misconfiguration when nil — so a missing field is caught at startup rather than on the first live request.Delete()now checksURLParamFunc != nilbefore dereferencing it, converting a potential nil-pointer panic into a clean500response for any caller that skipsValidate().Validate()method is covered by individual nil-field tests and a fully-configured happy-path test; theDelete()guard is covered by a dedicated HTTP-recorder test.Confidence Score: 5/5
Safe to merge — the changes are strictly additive startup checks and a defensive nil guard with no behavioural changes to happy-path request handling.
All three Validate() methods are straightforward nil-checks that mirror the existing MagicLinkHandler pattern. The new runtime guard in Delete() converts a nil-pointer panic into a clean HTTP 500, and every new branch is covered by a targeted unit test. No existing logic is modified.
No files require special attention.
Important Files Changed
Reviews (2): Last reviewed commit: "fix(handlers): add missing Validate chec..." | Re-trigger Greptile