Skip to content

Commit

Permalink
Add checks for defined stream ids (#1568)
Browse files Browse the repository at this point in the history
I don’t think this is happening, but want to rule it out.
  • Loading branch information
texuf authored Nov 19, 2024
1 parent c8812ef commit 3caa760
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,12 +2101,14 @@ export class Client
tags?: PlainMessage<Tags>,
retryCount?: number,
): Promise<{ prevMiniblockHash: Uint8Array; eventId: string; error?: AddEventResponse_Error }> {
const streamIdStr = streamIdAsString(streamId)
check(isDefined(streamIdStr) && streamIdStr !== '', 'streamId must be defined')
const event = await makeEvent(this.signerContext, payload, prevMiniblockHash)
const eventId = bin_toHexString(event.hash)
if (localId) {
// when we have a localId, we need to update the local event with the eventId
const stream = this.streams.get(streamId)
assert(stream !== undefined, 'unknown stream ' + streamIdAsString(streamId))
assert(stream !== undefined, 'unknown stream ' + streamIdStr)
stream.updateLocalEvent(localId, eventId, 'sending')
}

Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/syncedStreams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SyncCookie } from '@river-build/proto'
import { DLogger, dlog, dlogError, shortenHexString } from '@river-build/dlog'
import { DLogger, check, dlog, dlogError, shortenHexString } from '@river-build/dlog'
import { StreamRpcClient } from './makeStreamRpcClient'
import { SyncedStreamEvents } from './streamEvents'
import TypedEmitter from 'typed-emitter'
Expand Down Expand Up @@ -62,7 +62,9 @@ export class SyncedStreams {

public set(streamId: string | Uint8Array, stream: SyncedStream): void {
this.log('stream set', streamId)
this.streams.set(streamIdAsString(streamId), stream)
const id = streamIdAsString(streamId)
check(id.length > 0, 'streamId cannot be empty')
this.streams.set(id, stream)
}

public delete(inStreamId: string | Uint8Array): void {
Expand Down

0 comments on commit 3caa760

Please sign in to comment.