fix(milpacs): route errors to NotFound vs Internal#83
Merged
Conversation
Pure refactor — moves the fakeDatastore struct, all method impls, milpacs panic stubs, and withTicketsKey helper from tickets_test.go into a new shared file so the upcoming milpacs_test.go can reuse the same scaffolding. Zero behavior change; all existing tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add 8 function fields to fakeDatastore for the milpacs methods exercised by this PR, delegate their method bodies to those fields, add withMilpacsKey helper, and update the struct doc comment to drop the stale "until Task 2" caveat. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Propagate gorm.ErrRecordNotFound unwrapped from FindProfilesByUsername so the handler can distinguish 404 (no such user) from 500 (datastore failure) via errors.Is; adds two TDD tests anchoring the behaviour. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 22, 2026
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.
Summary
Fixes the long-standing
MilpacsServiceerror-routing bug: every datastore error mapped tocodes.NotFound(HTTP 404). DB outages, query timeouts, and genuine missing-record lookups were indistinguishable to consumers.Two distinct bug shapes get fixed in one bundled PR:
gorm.ErrRecordNotFoundand wrapped withfmt.Errorfwithout%w, destroying the sentinel. Now the datastore returnsresult.Errordirectly; handler addserrors.Is(err, gorm.ErrRecordNotFound)→codes.NotFound, everything else →codes.Internal. MirrorsTicketsService.Find()without capturingresult.Error, so DB outages produced empty slices with no error — handlers returnedHTTP 200 {Profiles: {}}. Handler'sif err != nil → 404branch was dead code. Now the datastore capturesresult.Errorand wraps with%w; handler maps any error tocodes.Internal.All
&proto.X{}error returns flipped tonil(gRPC ignores the message on error; matches the tickets convention).13 new unit tests via a shared
fakeDatastorelifted out oftickets_test.gointofake_datastore_test.go.No proto / OpenAPI / interface changes. No release cut.
Files
datastores/mysql.go— Pattern A unwrap on 5 single-row finders; Pattern Bresult.Errorcapture on 3 roster findersservers/grpc/grpc.go— handler updates on 7 RPCs (GetProfileusername + user_id,GetUserViaKeycloakId,GetUserViaDiscordId,GetGamertagProfile,GetRoster,GetLiteRoster,GetS1UniformsRoster)servers/grpc/fake_datastore_test.go— new shared test stubservers/grpc/milpacs_test.go— new, 13 unit testsservers/grpc/tickets_test.go—fakeDatastoreblock removed (moved to the new shared file)Already-correct RPCs untouched
SearchByPosition,GetAllRanks,GetPositionGroups,GetAwol— all four already route errors correctly via theInternalpattern. Listed for reviewer context, no code change.Out of scope (tracked as followup chore in the vault, blocked by this PR)
errors.New("cannot request null roster type")on 3 roster handlers (should becodes.InvalidArgument).Warn.Println(...)warn-but-continue (should early-returnInvalidArgument).fmt.Errorf("error generating profile")outliers without%w(FindProfileByKeycloakID,FindProfileByDiscordID, S1-uniforms inline loop).Test plan
go test ./...— 13 new milpacs tests + existing suite greengo vet ./... && go build ./...— cleanJarvis.A→ 200, bogus user → 404, combat roster → 200, post-docker stop/docker startcycle recovery → 200Coverage gap acknowledged
The Pattern-B unit tests stub the datastore method and verify the handler's mapping; they do not directly verify the datastore-side
result.Errorcapture. The planned end-to-enddocker stop xenforo-db → expect 500smoke can't isolate that path because the auth middleware (ValidateApiKey) also queries xenforo-db, so requests 401 before reaching the milpacs handlers. The datastore-side capture is verified by code inspection only. Reviewing the diff is the path of record.🤖 Generated with Claude Code