Skip to content

Errors returned by reducers contain stack traces #3959

@rekhoff

Description

@rekhoff

Steve reported that: Errors returned by reducers contain stack traces.
The client receives from a reducer that has throw new Exception("Message");:

System.Exception: Message
   at Module.Test3(ReducerContext )
   at ModuleRegistration.Test3.Invoke(BinaryReader , IReducerContext )
   at SpacetimeDB.Internal.Module.__call_reducer__(UInt32 id, UInt64 sender_0, UInt64 sender_1, UInt64 sender_2, UInt64 sender_3, UInt64 conn_id_0, UInt64 conn_id_1, Timestamp timestamp, BytesSource args, BytesSink error)

It was validated that both of these are happening on 1.11.1. Here's minimal code to trigger both this and #3960:

using SpacetimeDB;

public static partial class Module
{
    [Table]
    public partial struct Person
    {
        [PrimaryKey, AutoInc]
        public int Id;
        public string Name;
    }

    [Reducer]
    public static void Test1(ReducerContext ctx) => ctx.Db.Person.Insert(new Person { Name = "" }); //Works fine

    [Reducer]
    public static void Test2(ReducerContext ctx) => ctx.Db.Person.Insert(new Person { Name = null }); //Throws an exception

    [Reducer]
    public static void Test3(ReducerContext ctx) => throw new Exception("Message");
}

This issue may be resolved with a simple update to \crates\bindings-csharp\Runtime\Internal\Module.cs at line 315 to read:
var error_str = e.Message;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions