handler/session: add Validate() to catch nil Sessions and URLParamFunc at startup#289
Merged
Merged
Conversation
Copilot created this pull request from a session on behalf of
veverkap
May 20, 2026 14:44
View session
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.
SessionHandlerwas the only handler in the package without aValidate()method, meaning nilSessionsorURLParamFuncfields caused a runtime panic instead of a startup error.Changes
handler/session.go— addsValidate() errorfollowing the established handler pattern; returns a descriptive error ifSessionsorURLParamFuncis nilhandler/session_test.go— adds three cases: nilSessions, nilURLParamFunc, and a fully configured handlerGreptile Summary
This PR adds a
Validate()method toSessionHandler, catching nilSessionsandURLParamFuncfields at startup rather than allowing a nil-dereference panic at the first request. The implementation and error messages match the pattern used by every other handler in the package.handler/session.go:Validate()checksSessionsthenURLParamFuncfor nil, returning a descriptive error for each; no other logic is changed.handler/session_test.go: Three new test cases cover nilSessions, nilURLParamFunc, and a fully configured handler, consistent with existing test style.Confidence Score: 5/5
Safe to merge — the change is purely additive and touches no existing request-handling logic.
Both changed files are small and self-contained: a two-condition guard method and three matching tests. The implementation mirrors the pattern established by every other handler in the package, existing slog calls already pass context correctly, and no request paths are modified.
No files require special attention.
Important Files Changed
Sequence Diagram
sequenceDiagram participant App as Application Startup participant SH as SessionHandler participant Store as SessionStore participant UPF as URLParamFunc App->>SH: Validate() SH->>Store: "Sessions == nil?" alt Sessions is nil SH-->>App: error: Sessions is required else Sessions is set SH->>UPF: "URLParamFunc == nil?" alt URLParamFunc is nil SH-->>App: error: URLParamFunc is required else URLParamFunc is set SH-->>App: nil (valid) end endReviews (1): Last reviewed commit: "Add Validate() to SessionHandler with ni..." | Re-trigger Greptile