Skip to content

Inserting a null string into a table throws an exception #3960

@rekhoff

Description

@rekhoff

Steve reported that: Inserting a null string into a table throws an exception:

System.ArgumentNullException: ArgumentNull_Generic Arg_ParamName_Name, s
   ...
   at System.Text.UTF8Encoding.UTF8EncodingSealed.GetBytes(String )
   at SpacetimeDB.BSATN.String.Write(BinaryWriter , String )
   at Module.Person.WriteFields(BinaryWriter )
   at SpacetimeDB.BSATN.IStructuralReadWrite.ToBytes[Person](Person )
   at SpacetimeDB.Internal.ITableView`2[[SpacetimeDB.Internal.TableHandles.Person,[Module.Person]].DoInsert(Person )
   at SpacetimeDB.Internal.TableHandles.Person.Insert(Person )

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

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");
}

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