Skip to content

Commit 0e2a7e4

Browse files
committed
refactor: use SyncError instead of defects
1 parent 0b1b515 commit 0e2a7e4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/@livestore/common/src/sync/ClientSessionSyncProcessor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const makeClientSessionSyncProcessor = ({
100100
const eventDef = getEventDef(schema, name)
101101
const nextNumPair = EventSequenceNumber.nextPair({
102102
seqNum: baseEventSequenceNumber,
103-
isClient: eventDef.eventDef.options.clientOnly
103+
isClient: eventDef.eventDef.options.clientOnly,
104104
})
105105
baseEventSequenceNumber = nextNumPair.seqNum
106106
return new LiveStoreEvent.EncodedWithMeta(
@@ -125,13 +125,13 @@ export const makeClientSessionSyncProcessor = ({
125125
)
126126

127127
if (mergeResult._tag === 'unexpected-error') {
128-
return yield* Effect.die(new Error(`Unexpected error in client-session-sync-processor: ${mergeResult.message}`))
128+
return yield* new SyncError({ cause: mergeResult.message })
129129
}
130130

131131
if (TRACE_VERBOSE) yield* Effect.annotateCurrentSpan({ mergeResult: JSON.stringify(mergeResult) })
132132

133133
if (mergeResult._tag !== 'advance') {
134-
return yield* Effect.die(new Error(`Expected advance, got ${mergeResult._tag}`))
134+
return yield* new SyncError({ cause: `Expected advance, got ${mergeResult._tag}` })
135135
}
136136

137137
syncStateRef.current = mergeResult.newSyncState
@@ -206,7 +206,7 @@ export const makeClientSessionSyncProcessor = ({
206206

207207
// NOTE We need to lazily call `.pull` as we want the cursor to be updated
208208
yield* Stream.suspend(() =>
209-
clientSession.leaderThread.events.pull({ cursor: syncStateRef.current.upstreamHead }),
209+
clientSession.leaderThread.events.pull({ cursor: syncStateRef.current.upstreamHead }),
210210
).pipe(
211211
Stream.tap(({ payload }) =>
212212
Effect.gen(function* () {
@@ -230,7 +230,7 @@ export const makeClientSessionSyncProcessor = ({
230230
}
231231

232232
syncStateRef.current = mergeResult.newSyncState
233-
syncStateUpdateQueue.offer(mergeResult.newSyncState).pipe(Effect.runSync)
233+
yield* syncStateUpdateQueue.offer(mergeResult.newSyncState)
234234

235235
if (mergeResult._tag === 'rebase') {
236236
span.addEvent('merge:pull:rebase', {
@@ -355,7 +355,7 @@ export interface ClientSessionSyncProcessor {
355355
{
356356
writeTables: Set<string>
357357
},
358-
never
358+
SyncError
359359
>
360360
boot: Effect.Effect<void, UnexpectedError, Scope.Scope>
361361
/**

0 commit comments

Comments
 (0)