SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

`OnUnhandledReducerError` in client SDKs

Open gefjon opened this issue 9 months ago • 4 comments

Name not yet decided. Semantics basically locked in by BitCraft needs. Specifically:

When receiving a TransactionUpdate for a known reducer with status Failed or OutOfEnergy, check if there are any callbacks registered on that reducer. If none are registered, invoke the OnUnhandledReducerError with a ReducerEventContext containing the failed reducer and with an Error/Exception object that contains the error message.

Callbacks are of the type FnMut(&module_bindings::ReducerEventContext, sdk::Error).

For the OutOfEnergy case, the passed Error should be distinguishable as meaning out of energy.

Callbacks are registered and removed directly on the DbContext. In Rust, this means the trait DbContext has methods on_unhandled_reducer_error(&self, callback) -> OnUnhandledReducerErrorCallbackId and remove_on_unhandled_reducer_error(&self, callback_id: OnUnhandledReducerErrorCallbackId).

This is high priority in C#, as BitCraft needs this functionality. It is significantly lower priority in Rust and TypeScript.

gefjon avatar Mar 27 '25 16:03 gefjon

Do you know if there's a time-sensitive need for this, besides "in time for the next bitcraft milestone"?

bfops avatar Mar 28 '25 17:03 bfops

Well, it needs to be done with enough lead time for the BitCraft team to use it in their code and properly test their code.

gefjon avatar Mar 28 '25 19:03 gefjon

On the C# side, it seems that the state for this will need to be held inside RemoteReducers rather than DbConnection. However, as phoebe pointed out to me, it's probably still better if the registration stuff goes on DbConnection so that there is no confusion when there is a reducer named unhandled_reducer_error. I think that basically makes sense -- DbConnection can call some sort of internal method on RemoteReducers to make this happen. I suspect something similar will hold in Rust and Typescript.

kazimuth avatar Mar 31 '25 20:03 kazimuth

The C# stuff is in review. I know we like to keep parity between our SDKs, so should we treat the rest of this as a P1 as well?

bfops avatar Apr 21 '25 18:04 bfops