Repository navigation
Conversation
|
@solaawojobi00-bit Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…t-outbox-fail-fast # Conflicts: # backend/src/eventOutbox.ts
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.
Fail fast when the Prisma client is missing the
eventOutboxmodelProblem
EventOutboxService.writeEventcallsprisma.eventOutbox.create(...)directly. If the Prisma client has noeventOutboxdelegate (for example, a stale generated client or an execution context without the model), the call throwsTypeError: Cannot read properties of undefined (reading 'create'). None of the call sites let that error through:vaultEndpoints.tscallswriteEventin the background (void … .catch(log)), so the failure is only logged and the event is silently lost.start()wraps everyprocessOutbox()poll in.catch(log), andprocessOutboxhas its own try/catch, so the background processor keeps logging the same error on every cycle.eventOutboxstart()throws at boot with a clear messagewriteEventwith missing modelTypeError: Cannot read properties of undefined, swallowed by callermissing the eventOutbox modelerrorreplayOnStartupwith missing modelTypeError, loggedSolution
Add a single guard,
assertEventOutboxModelAvailable(), and call it at the service's entry points.start()is called synchronously and without error handling inindex.ts, so the guard there makes startup fail immediately (the fail-fast during initialization the issue asks for). The guards inwriteEventandreplayOnStartupreplace theTypeErrorwith a message that says how to fix it.Changes
backend/src/eventOutbox.tsstart(), beforeisRunningis set, so a failed start leaves the processor inactive and no timers are created.writeEvent()andreplayOnStartup().clientparameter defaults to the sharedprismainstance, so the function can be unit-tested without mocking modules.backend/src/__tests__/eventOutboxModelGuard.test.ts(new)This file uses
jest.isolateModules+jest.doMock('../prisma')to load the service against a client that has noeventOutboxmodel. The existingeventOutbox.test.tssuite still runs against the real database.Regression Tests
assertEventOutboxModelAvailablethrows for undefined / null /{}/{ eventOutbox: {} }eventOutbox.createis a functionstart()throws synchronously andisActivestaysfalsewriteEventrejects withmissing the eventOutbox modelreplayOnStartuprejects withmissing the eventOutbox modeleventOutbox.test.tssuite passesTesting
npx eslint src/eventOutbox.ts src/__tests__/eventOutboxModelGuard.test.tsreports no problems, andtsc --noEmitreports no errors in the changed files.Notes for Reviewers
.catch(log)pattern invaultEndpoints.tsis unchanged: with the boot-time guard, a server that is running is known to have the model, so request handling doesn't need to change.git revert. There is no schema or state change.Closes #1380