Skip to content

Commit 8c1b4a9

Browse files
authored
Implement OnUnhandledReducerError (#295)
## Description of Changes SDK side of clockworklabs/SpacetimeDB#2636 Addresses #281 ## API - [ ] This is an API breaking change to the SDK ## Requires SpacetimeDB PRs clockworklabs/SpacetimeDB#2636 ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: jgilles/on-unhandled-reducer-error ## Testing - [ ] Add a test that this works to the regression-tests example module
1 parent 5df6617 commit 8c1b4a9

File tree

12 files changed

+608
-359
lines changed

12 files changed

+608
-359
lines changed

examples~/quickstart-chat/client/module_bindings/Reducers/IdentityConnected.g.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ public sealed partial class RemoteReducers : RemoteBase
1717

1818
public bool InvokeIdentityConnected(ReducerEventContext ctx, Reducer.IdentityConnected args)
1919
{
20-
if (OnIdentityConnected == null) return false;
20+
if (OnIdentityConnected == null)
21+
{
22+
if (InternalOnUnhandledReducerError != null)
23+
{
24+
switch (ctx.Event.Status)
25+
{
26+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
27+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
28+
}
29+
}
30+
return false;
31+
}
2132
OnIdentityConnected(
2233
ctx
2334
);

examples~/quickstart-chat/client/module_bindings/Reducers/IdentityDisconnected.g.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ public sealed partial class RemoteReducers : RemoteBase
1717

1818
public bool InvokeIdentityDisconnected(ReducerEventContext ctx, Reducer.IdentityDisconnected args)
1919
{
20-
if (OnIdentityDisconnected == null) return false;
20+
if (OnIdentityDisconnected == null)
21+
{
22+
if (InternalOnUnhandledReducerError != null)
23+
{
24+
switch (ctx.Event.Status)
25+
{
26+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
27+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
28+
}
29+
}
30+
return false;
31+
}
2132
OnIdentityDisconnected(
2233
ctx
2334
);

examples~/quickstart-chat/client/module_bindings/Reducers/SendMessage.g.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@ public void SendMessage(string text)
2222

2323
public bool InvokeSendMessage(ReducerEventContext ctx, Reducer.SendMessage args)
2424
{
25-
if (OnSendMessage == null) return false;
25+
if (OnSendMessage == null)
26+
{
27+
if (InternalOnUnhandledReducerError != null)
28+
{
29+
switch (ctx.Event.Status)
30+
{
31+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
32+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
33+
}
34+
}
35+
return false;
36+
}
2637
OnSendMessage(
2738
ctx,
2839
args.Text

examples~/quickstart-chat/client/module_bindings/Reducers/SetName.g.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@ public void SetName(string name)
2222

2323
public bool InvokeSetName(ReducerEventContext ctx, Reducer.SetName args)
2424
{
25-
if (OnSetName == null) return false;
25+
if (OnSetName == null)
26+
{
27+
if (InternalOnUnhandledReducerError != null)
28+
{
29+
switch (ctx.Event.Status)
30+
{
31+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
32+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
33+
}
34+
}
35+
return false;
36+
}
2637
OnSetName(
2738
ctx,
2839
args.Name

0 commit comments

Comments
 (0)