diff --git a/clients/ts/FunctionalTests/Startup.cs b/clients/ts/FunctionalTests/Startup.cs index 7b07fd5abc..bf216e13fc 100644 --- a/clients/ts/FunctionalTests/Startup.cs +++ b/clients/ts/FunctionalTests/Startup.cs @@ -24,7 +24,10 @@ namespace FunctionalTests public void ConfigureServices(IServiceCollection services) { services.AddConnections(); - services.AddSignalR() + services.AddSignalR(options => + { + options.EnableDetailedErrors = true; + }) .AddJsonProtocol(options => { // we are running the same tests with JSON and MsgPack protocols and having diff --git a/clients/ts/FunctionalTests/ts/HubConnectionTests.ts b/clients/ts/FunctionalTests/ts/HubConnectionTests.ts index 49f85be013..2f7a92c51b 100644 --- a/clients/ts/FunctionalTests/ts/HubConnectionTests.ts +++ b/clients/ts/FunctionalTests/ts/HubConnectionTests.ts @@ -125,7 +125,7 @@ describe("hubConnection", () => { }); it("rethrows an exception from the server when invoking", (done) => { - const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server."; + const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server. InvalidOperationException: An error occurred."; const hubConnection = new HubConnection(TESTHUBENDPOINT_URL, { logger: TestLogger.instance, protocol, @@ -198,7 +198,7 @@ describe("hubConnection", () => { }); it("rethrows an exception from the server when streaming", (done) => { - const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server."; + const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server. InvalidOperationException: An error occurred."; const hubConnection = new HubConnection(TESTHUBENDPOINT_URL, { logger: TestLogger.instance, protocol, @@ -353,7 +353,7 @@ describe("hubConnection", () => { }); hubConnection.onclose((error) => { - expect(error.message).toEqual("Server returned an error on close: Connection closed with an error."); + expect(error.message).toEqual("Server returned an error on close: Connection closed with an error. InvalidOperationException: Unable to resolve service for type 'System.Object' while attempting to activate 'FunctionalTests.UncreatableHub'."); done(); }); hubConnection.start(); diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs index e0be88c850..ec75f9468e 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs @@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol hasResult = false; break; default: - throw new FormatException("Invalid invocation result kind."); + throw new InvalidDataException("Invalid invocation result kind."); } return ApplyHeaders(headers, new CompletionMessage(invocationId, error, result, hasResult)); @@ -231,7 +231,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol if (parameterTypes.Count != argumentCount) { - throw new FormatException( + throw new InvalidDataException( $"Invocation provides {argumentCount} argument(s) but target expects {parameterTypes.Count}."); } @@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol } catch (Exception ex) { - throw new FormatException("Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex); + throw new InvalidDataException("Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex); } } @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol WriteCloseMessage(closeMessage, packer); break; default: - throw new FormatException($"Unexpected message type: {message.GetType().Name}"); + throw new InvalidDataException($"Unexpected message type: {message.GetType().Name}"); } } @@ -435,7 +435,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol msgPackException = e; } - throw new FormatException($"Reading '{field}' as Int32 failed.", msgPackException); + throw new InvalidDataException($"Reading '{field}' as Int32 failed.", msgPackException); } private static string ReadString(Unpacker unpacker, string field) @@ -460,7 +460,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol msgPackException = e; } - throw new FormatException($"Reading '{field}' as String failed.", msgPackException); + throw new InvalidDataException($"Reading '{field}' as String failed.", msgPackException); } private static bool ReadBoolean(Unpacker unpacker, string field) @@ -478,7 +478,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol msgPackException = e; } - throw new FormatException($"Reading '{field}' as Boolean failed.", msgPackException); + throw new InvalidDataException($"Reading '{field}' as Boolean failed.", msgPackException); } private static long ReadMapLength(Unpacker unpacker, string field) @@ -496,7 +496,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol msgPackException = e; } - throw new FormatException($"Reading map length for '{field}' failed.", msgPackException); + throw new InvalidDataException($"Reading map length for '{field}' failed.", msgPackException); } private static long ReadArrayLength(Unpacker unpacker, string field) @@ -514,7 +514,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol msgPackException = e; } - throw new FormatException($"Reading array length for '{field}' failed.", msgPackException); + throw new InvalidDataException($"Reading array length for '{field}' failed.", msgPackException); } private static object DeserializeObject(Unpacker unpacker, Type type, string field) @@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol msgPackException = ex; } - throw new FormatException($"Deserializing object of the `{type.Name}` type for '{field}' failed.", msgPackException); + throw new InvalidDataException($"Deserializing object of the `{type.Name}` type for '{field}' failed.", msgPackException); } internal static SerializationContext CreateDefaultSerializationContext() diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 4fc1d4bc7e..5158f4b65b 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -415,7 +415,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests var channel = await connection.StreamAsChannelAsync("StreamException").OrTimeout(); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); - Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server.", ex.Message); + Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server. InvalidOperationException: Error occurred while streaming.", ex.Message); } catch (Exception ex) { @@ -469,7 +469,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests await connection.StartAsync().OrTimeout(); var ex = await Assert.ThrowsAsync(() => connection.InvokeAsync("Echo", "p1", 42)).OrTimeout(); - Assert.Equal("Failed to invoke 'Echo' due to an error on the server.", ex.Message); + Assert.Equal("Failed to invoke 'Echo' due to an error on the server. InvalidDataException: Invocation provides 2 argument(s) but target expects 1.", ex.Message); } catch (Exception ex) { @@ -553,7 +553,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests var channel = await connection.StreamAsChannelAsync("Stream", 42, 42); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); - Assert.Equal("Failed to invoke 'Stream' due to an error on the server.", ex.Message); + Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Invocation provides 2 argument(s) but target expects 1.", ex.Message); } catch (Exception ex) { @@ -581,7 +581,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests var channel = await connection.StreamAsChannelAsync("Stream", "xyz"); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); - Assert.Equal("Failed to invoke 'Stream' due to an error on the server.", ex.Message); + Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex.Message); } catch (Exception ex) { diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs index 1d7bbb644f..3af45241be 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs @@ -20,7 +20,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests public void ConfigureServices(IServiceCollection services) { - services.AddSignalR() + services.AddSignalR(options => + { + options.EnableDetailedErrors = true; + }) .AddMessagePackProtocol(); services.AddAuthorization(options => { diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs index 2693c74908..34b6d81570 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs @@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol var buffer = Frame(Pack(testData.Encoded)); var binder = new TestBinder(new[] { typeof(string) }, typeof(string)); var data = new ReadOnlySequence(buffer); - var exception = Assert.Throws(() => _hubProtocol.TryParseMessage(ref data, binder, out _)); + var exception = Assert.Throws(() => _hubProtocol.TryParseMessage(ref data, binder, out _)); Assert.Equal(testData.ErrorMessage, exception.Message); } @@ -413,7 +413,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol var binder = new TestBinder(new[] { typeof(string) }, typeof(string)); var data = new ReadOnlySequence(buffer); _hubProtocol.TryParseMessage(ref data, binder, out var message); - var exception = Assert.Throws(() => ((HubMethodInvocationMessage)message).Arguments); + var exception = Assert.Throws(() => ((HubMethodInvocationMessage)message).Arguments); Assert.Equal(testData.ErrorMessage, exception.Message); } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs index b6ec249ed7..2ed9cb4b61 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs @@ -12,7 +12,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void ConfigureServices(IServiceCollection services) { services.AddConnections(); - services.AddSignalR(); + services.AddSignalR(options => + { + options.EnableDetailedErrors = true; + }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env)