Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4d2e4c1
Added a SpacetimeDBException to C# SDK to aid in debugging
rekhoff Oct 8, 2025
5d01dcf
Update Lints
rekhoff Oct 8, 2025
71ce0f4
Merge branch 'master' into rekhoff/custom-csharp-sdk-exceptions
rekhoff Oct 8, 2025
70d69b7
Updated codegen csharp snapshot to include new exception type
rekhoff Oct 8, 2025
cd3e433
Updated csharp example project module binds
rekhoff Oct 8, 2025
0f35f58
Updated Blackholio's csharp bindings
rekhoff Oct 8, 2025
49fb5cf
Adding Unity meta data file for Exceptions.cs in C# SDK
rekhoff Oct 9, 2025
7a4c6f6
Merge branch 'master' into rekhoff/custom-csharp-sdk-exceptions
rekhoff Oct 9, 2025
2bb5ede
Merge branch 'master' into rekhoff/custom-csharp-sdk-exceptions
rekhoff Oct 14, 2025
dcbbb3e
Merge branch 'master' into rekhoff/custom-csharp-sdk-exceptions
rekhoff Oct 15, 2025
f2b117f
Update regression-test to use local ClientSDK
rekhoff Oct 16, 2025
98d37bf
Merge branch 'master' into rekhoff/custom-csharp-sdk-exceptions
rekhoff Oct 16, 2025
57fecd1
Merge branch 'master' into rekhoff/custom-csharp-sdk-exceptions
rekhoff Oct 20, 2025
a1c5445
[bfops/fix-csharp-quickstart-smoketest]: C# quickstart test properly …
bfops Oct 23, 2025
78e6da9
[bfops/fix-csharp-quickstart-smoketest]: review
bfops Oct 23, 2025
dca3348
[bfops/fix-csharp-quickstart-smoketest]: revert
bfops Oct 23, 2025
d560994
[bfops/fix-csharp-quickstart-smoketest]: fix
bfops Oct 23, 2025
eff3cbc
[bfops/fix-csharp-quickstart-smoketest]: fix
bfops Oct 23, 2025
98cd067
[bfops/fix-csharp-quickstart-smoketest]: fix
bfops Oct 23, 2025
ecfa9e1
[rekhoff/custom-csharp-sdk-exceptions]: Merge remote-tracking branch …
bfops Oct 23, 2025
56f80ef
[rekhoff/custom-csharp-sdk-exceptions]: Merge remote-tracking branch …
bfops Oct 23, 2025
ce72b9c
[rekhoff/custom-csharp-sdk-exceptions]: Merge remote-tracking branch …
bfops Oct 23, 2025
0670e62
[rekhoff/custom-csharp-sdk-exceptions]: Merge remote-tracking branch …
bfops Oct 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/codegen/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ impl Lang for Csharp<'_> {
"\"{reducer_str_name}\" => BSATNHelpers.Decode<Reducer.{reducer_name}>(encodedArgs),"
);
}
writeln!(
output,
r#""" => throw new SpacetimeDBEmptyReducerNameException("Reducer name is empty"),"#
);
writeln!(
output,
r#"var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {{reducer}}")"#
Expand Down
2 changes: 2 additions & 0 deletions crates/codegen/tests/snapshots/codegen__codegen_csharp.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/codegen/tests/codegen.rs
assertion_line: 37
expression: outfiles
---
"Reducers/Add.g.cs" = '''
Expand Down Expand Up @@ -1463,6 +1464,7 @@ namespace SpacetimeDB
"say_hello" => BSATNHelpers.Decode<Reducer.SayHello>(encodedArgs),
"test" => BSATNHelpers.Decode<Reducer.Test>(encodedArgs),
"test_btree_index_args" => BSATNHelpers.Decode<Reducer.TestBtreeIndexArgs>(encodedArgs),
"" => throw new SpacetimeDBEmptyReducerNameException("Reducer name is empty"),
var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
};
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SpacetimeDB.ClientSDK" Version="1.5.0" />
<ProjectReference Include="../../../../SpacetimeDB.ClientSDK.csproj" />
Comment thread
rekhoff marked this conversation as resolved.
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 138 additions & 0 deletions sdks/csharp/src/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;
using System.Runtime.Serialization;

namespace SpacetimeDB
{
/// <summary>
/// The base class for all SpacetimeDB SDK exceptions.
/// This allows users to catch all SpacetimeDB-specific exceptions in one catch block
/// or configure their debugger to ignore them.
/// </summary>
[Serializable]
public class SpacetimeDBException : Exception
{
// Base HRESULT for SpacetimeDB exceptions (0x8A000000 is in the user-defined range)
private const int SPACETIMEDB_HRESULT_BASE = unchecked((int)0x8A000000);

// Specific HRESULTs for different exception types
public const int SPACETIMEDB_EMPTY_REDUCER_NAME = SPACETIMEDB_HRESULT_BASE + 1;

public SpacetimeDBException()
: base()
{
HResult = SPACETIMEDB_HRESULT_BASE;
}

public SpacetimeDBException(string? message)
: base(message)
{
HResult = SPACETIMEDB_HRESULT_BASE;
}

public SpacetimeDBException(string? message, Exception? innerException)
: base(message, innerException)
{
HResult = SPACETIMEDB_HRESULT_BASE;
}

protected SpacetimeDBException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

/// <summary>
/// The exception that is thrown when one of the arguments provided to a method is not valid.
/// This is the base class for all SpacetimeDB argument exceptions.
/// </summary>
[Serializable]
public class SpacetimeDBArgumentException : SpacetimeDBException
{
private readonly string? _paramName;

public SpacetimeDBArgumentException()
: base("Value does not fall within the expected range.") { }

public SpacetimeDBArgumentException(string? message)
: base(message) { }

public SpacetimeDBArgumentException(string? message, Exception? innerException)
: base(message, innerException) { }

public SpacetimeDBArgumentException(
string? message,
string? paramName,
Exception? innerException
)
: base(message, innerException)
{
_paramName = paramName;
}

public SpacetimeDBArgumentException(string? message, string? paramName)
: base(message)
{
_paramName = paramName;
}

protected SpacetimeDBArgumentException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
_paramName = info.GetString("ParamName");
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("ParamName", _paramName, typeof(string));
}

public virtual string? ParamName => _paramName;
}

/// <summary>
/// The exception that is thrown when an empty reducer name is received from the server.
/// This is a known condition that is handled internally by the SpacetimeDB client.
/// </summary>
[Serializable]
public class SpacetimeDBEmptyReducerNameException : SpacetimeDBArgumentException
{
public SpacetimeDBEmptyReducerNameException()
: base("Empty reducer name received from server", (string?)null)
{
HResult = SPACETIMEDB_EMPTY_REDUCER_NAME;
}

public SpacetimeDBEmptyReducerNameException(string? paramName)
: base("Empty reducer name received from server", paramName)
{
HResult = SPACETIMEDB_EMPTY_REDUCER_NAME;
}

public SpacetimeDBEmptyReducerNameException(string? message, string? paramName)
: base(message, paramName)
{
HResult = SPACETIMEDB_EMPTY_REDUCER_NAME;
}

public SpacetimeDBEmptyReducerNameException(string? message, Exception? innerException)
: base(message, null, innerException)
{
HResult = SPACETIMEDB_EMPTY_REDUCER_NAME;
}

public SpacetimeDBEmptyReducerNameException(
string? message,
string? paramName,
Exception? innerException
)
: base(message, paramName, innerException)
{
HResult = SPACETIMEDB_EMPTY_REDUCER_NAME;
}

protected SpacetimeDBEmptyReducerNameException(
SerializationInfo info,
StreamingContext context
)
: base(info, context) { }
}
}
11 changes: 11 additions & 0 deletions sdks/csharp/src/Exceptions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading