Skip to content

Commit 0866367

Browse files
authored
Handle unknown transactions without erroring. (clockworklabs#3858)
# Description of Changes Don't throw an error if there is no `reducerInfo`. The code was previously trying to handle the case of an unknown reducer, but was effectively asserting that the reducerInfo existed too soon. Now we should be fine handling a transaction, even if we can't determine reducer information for it. # Expected complexity level and risk 1. # Testing I tested this by running the quickstart chat app, and using the CLI to delete rows (via `spacetime sql`). Before this change, the client errors, but now it handles it correctly. I also tested with the repro in clockworklabs#3817
1 parent bea7a7d commit 0866367

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

crates/bindings-typescript/src/sdk/db_connection_impl.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import type {
5252
ReducersView,
5353
SetReducerFlags,
5454
SubscriptionEventCallback,
55+
UntypedReducerDef,
5556
} from './reducers.ts';
5657
import type { ClientDbView } from './db_view.ts';
5758
import type { UntypedTableDef } from '../lib/table.ts';
@@ -749,20 +750,22 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
749750
}
750751
case 'TransactionUpdate': {
751752
let reducerInfo = message.reducerInfo;
752-
let unknownTransaction = false;
753-
let reducerArgs: InferTypeOfRow<typeof reducer.params> | undefined;
754-
const reducer = this.#remoteModule.reducers.find(
755-
t => t.name === reducerInfo!.reducerName
756-
)!;
757-
if (!reducerInfo) {
758-
unknownTransaction = true;
759-
} else {
760-
// TODO: performance
753+
754+
const reducer: UntypedReducerDef | undefined =
755+
reducerInfo === undefined
756+
? undefined
757+
: this.#remoteModule.reducers.find(
758+
t => t.name === reducerInfo!.reducerName
759+
);
760+
let reducerArgs: UntypedReducerDef['params'] | undefined = undefined;
761+
762+
let unknownTransaction = reducer === undefined;
763+
if (reducer) {
761764
try {
762-
const reader = new BinaryReader(reducerInfo.args as Uint8Array);
765+
const reader = new BinaryReader(reducerInfo!.args as Uint8Array);
763766
reducerArgs = ProductType.deserializeValue(
764767
reader,
765-
reducer?.paramsType
768+
reducer.paramsType
766769
);
767770
} catch {
768771
// This should only be printed in development, since it's
@@ -786,7 +789,6 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
786789
}
787790
return;
788791
}
789-
790792
// At this point, we know that `reducerInfo` is not null because
791793
// we return if `unknownTransaction` is true.
792794
reducerInfo = reducerInfo!;
@@ -808,7 +810,7 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
808810
tag: 'Reducer',
809811
value: reducerEvent,
810812
};
811-
const eventContext = this.#makeEventContext(event);
813+
const eventContext = this.#makeEventContext(event as any);
812814
const reducerEventContext = {
813815
...eventContext,
814816
event: reducerEvent,

0 commit comments

Comments
 (0)