diff --git a/crates/bindings-csharp/Runtime/Internal/Module.cs b/crates/bindings-csharp/Runtime/Internal/Module.cs index c9f528258d8..0ca39977b86 100644 --- a/crates/bindings-csharp/Runtime/Internal/Module.cs +++ b/crates/bindings-csharp/Runtime/Internal/Module.cs @@ -312,7 +312,7 @@ BytesSink error } catch (Exception e) { - var error_str = e.ToString(); + var error_str = e.Message ?? e.GetType().FullName; var error_bytes = System.Text.Encoding.UTF8.GetBytes(error_str); error.Write(error_bytes); return Errno.HOST_CALL_FAILURE; diff --git a/sdks/csharp/examples~/regression-tests/client/Program.cs b/sdks/csharp/examples~/regression-tests/client/Program.cs index 993de658d88..f1274b78188 100644 --- a/sdks/csharp/examples~/regression-tests/client/Program.cs +++ b/sdks/csharp/examples~/regression-tests/client/Program.cs @@ -12,6 +12,7 @@ const string HOST = "http://localhost:3000"; const string DBNAME = "btree-repro"; +const string THROW_ERROR_MESSAGE = "this is an error"; DbConnection ConnectToDB() { @@ -87,6 +88,7 @@ void OnConnected(DbConnection conn, Identity identity, string authToken) { Log.Info($"Got OnUnhandledReducerError: {exception}"); waiting--; + ValidateReducerErrorDoesNotContainStackTrace(exception); ValidateBTreeIndexes(ctx); ValidateNullableVecView(ctx); }; @@ -167,6 +169,17 @@ void ValidateNullableVecView( } } +void ValidateReducerErrorDoesNotContainStackTrace(Exception exception) +{ + Debug.Assert( + exception.Message == THROW_ERROR_MESSAGE, + $"Expected reducer error message '{THROW_ERROR_MESSAGE}', got '{exception.Message}'" + ); + Debug.Assert(!exception.Message.Contains("\n"), "Reducer error message should not contain newline"); + Debug.Assert(!exception.Message.Contains("\r"), "Reducer error message should not contain newline"); + Debug.Assert(!exception.Message.Contains(" at "), "Reducer error message should not contain stack trace"); +} + void OnSubscriptionApplied(SubscriptionEventContext context) { applied = true; @@ -187,7 +200,7 @@ void OnSubscriptionApplied(SubscriptionEventContext context) Log.Debug("Calling ThrowError"); waiting++; - context.Reducers.ThrowError("this is an error"); + context.Reducers.ThrowError(THROW_ERROR_MESSAGE); // RemoteQuery test Log.Debug("Calling RemoteQuery");