Repository navigation
[AI:zf-builder] refactor(server): dedup WebSocket upgrade-error classification across websocket.go and migrate.go (Ponytail Rung 2) - #191
Merged
Conversation
… websocket.go and migrate.go (Ponytail Rung 2) Task: zf-z-aaaf65bb
Deploying zerohub with
|
| Latest commit: |
2df84c6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f1716ac7.zerohub.pages.dev |
| Branch Preview URL: | https://task-zf-z-aaaf65bb.zerohub.pages.dev |
ntsd
commented
Nov 21, 2026
ntsd
left a comment
Contributor
Author
There was a problem hiding this comment.
[AI:zf-reviewer] [Reviewer Feedback] Round 1: Approved for human review.
Scope verified against the real diff (git diff origin/main...HEAD): exactly 3 files, no lockfile churn, no drive-by reformatting, no unrelated files. The pre-digested diff matches the committed change byte-for-byte.
Correctness / dedup
websocket.HandshakeErrornow appears in exactly one place: the new unexported helperwrapUpgradeErrorin websocket.go (grep over pkg/+cmd/ non-test confirms a single remaining occurrence). Both call sites (websocket.goUpgrade andmigrate.goForwardMigrate) delegate to it.- Error message strings are preserved verbatim ("websocket handshake: " / "websocket upgrade error: "), so no observable behavior change.
- The out-of-scope
finishUpgradeFailurelog site (websocket.go ~line 262,log.Error().Err(fmt.Errorf("websocket upgrade error: %w", err))) was correctly left untouched — it has a different context (logging with%wvs returning to caller), exactly as the task specified not to fold it in.
Tests
- New
wrap_upgrade_error_test.gopins all three behaviors: the HandshakeError branch (prefix "websocket handshake: "), the generic non-HandshakeError branch (exact full-string match, so the original message is preserved), and the nil boundary. These are real assertions on distinct branches, not tautological/mock-only. - Full server suite green:
go build ./... && go vet ./... && go test ./...all pass; the 3 new tests pass under-run TestWrapUpgradeError -v.
Ponytail / diff hygiene
- Rung 2 (codebase reuse): a genuine in-package dedup with net LOC reduction — ~10 duplicated lines become one 5-line helper plus two one-line call sites.
- Rungs 1/6 (YAGNI/simplicity): the helper is justified by exactly 2 real call sites with non-trivial classification (type assertion + two distinct labels); not a premature abstraction, not a single-caller factory.
- Rungs 3/5: no new external dependencies (only
errors/strings/testing+ already-importedgithub.com/fasthttp/websocketin the test). - No leftover debug code.
PR #191 is mergeable and not a draft. No changes requested.
CONVENTION: For dedup refactors in pkg/handler, keep the classification helper local (unexported, single package) and add a focused unit test pinning each branch (handshake vs generic vs nil boundary); leave logging-context %w sites out of scope.
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.
[AI:zf-builder] Task: zf-z-aaaf65bb
Automated PR for task zf-z-aaaf65bb
Completed by: @zf-builder