Skip to content

Commit 3c60e1f

Browse files
committed
Fix error messages to use friendly type name
1 parent c44ed0f commit 3c60e1f

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

src/Foundatio.Mediator.Abstractions/Mediator.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ private InvokeAsyncDelegate GetInvokeAsyncDelegate(Type messageType)
6060
var handlersList = handlers.ToList();
6161

6262
if (handlersList.Count == 0)
63-
throw new InvalidOperationException($"No handler found for message type {mt.FullName}");
63+
throw new InvalidOperationException($"No handler found for message type {MessageTypeKey.Get(mt)}");
6464

6565
if (handlersList.Count > 1)
66-
throw new InvalidOperationException($"Multiple handlers found for message type {mt.FullName}. Use PublishAsync for multiple handlers.");
66+
throw new InvalidOperationException($"Multiple handlers found for message type {MessageTypeKey.Get(mt)}. Use PublishAsync for multiple handlers.");
6767

6868
var handler = handlersList.First();
6969
return async (mediator, msg, ct) => await handler.HandleAsync(mediator, msg, ct, null);
@@ -79,14 +79,14 @@ private InvokeDelegate GetInvokeDelegate(Type messageType)
7979
var handlersList = handlers.ToList();
8080

8181
if (handlersList.Count == 0)
82-
throw new InvalidOperationException($"No handler found for message type {mt.FullName}");
82+
throw new InvalidOperationException($"No handler found for message type {MessageTypeKey.Get(mt)}");
8383

8484
if (handlersList.Count > 1)
85-
throw new InvalidOperationException($"Multiple handlers found for message type {mt.FullName}. Use Publish for multiple handlers.");
85+
throw new InvalidOperationException($"Multiple handlers found for message type {MessageTypeKey.Get(mt)}. Use Publish for multiple handlers.");
8686

8787
var handler = handlersList.First();
8888
if (handler.IsAsync)
89-
throw new InvalidOperationException($"Cannot use synchronous Invoke with async-only handler for message type {mt.FullName}. Use InvokeAsync instead.");
89+
throw new InvalidOperationException($"Cannot use synchronous Invoke with async-only handler for message type {MessageTypeKey.Get(mt)}. Use InvokeAsync instead.");
9090

9191
return (mediator, msg, ct) => handler.Handle!(mediator, msg, ct, null);
9292
});
@@ -101,10 +101,10 @@ private InvokeAsyncResponseDelegate GetInvokeAsyncResponseDelegate(Type messageT
101101
var handlersList = handlers.ToList();
102102

103103
if (handlersList.Count == 0)
104-
throw new InvalidOperationException($"No handler found for message type {key.MessageType.FullName}");
104+
throw new InvalidOperationException($"No handler found for message type {MessageTypeKey.Get(key.MessageType)}");
105105

106106
if (handlersList.Count > 1)
107-
throw new InvalidOperationException($"Multiple handlers found for message type {key.MessageType.FullName}. Use PublishAsync for multiple handlers.");
107+
throw new InvalidOperationException($"Multiple handlers found for message type {MessageTypeKey.Get(key.MessageType)}. Use PublishAsync for multiple handlers.");
108108

109109
var handler = handlersList.First();
110110
return (mediator, msg, ct) => handler.HandleAsync(mediator, msg, ct, key.ResponseType);
@@ -120,14 +120,14 @@ private InvokeResponseDelegate GetInvokeResponseDelegate(Type messageType, Type
120120
var handlersList = handlers.ToList();
121121

122122
if (handlersList.Count == 0)
123-
throw new InvalidOperationException($"No handler found for message type {key.MessageType.FullName}");
123+
throw new InvalidOperationException($"No handler found for message type {MessageTypeKey.Get(key.MessageType)}");
124124

125125
if (handlersList.Count > 1)
126-
throw new InvalidOperationException($"Multiple handlers found for message type {key.MessageType.FullName}. Use Publish for multiple handlers.");
126+
throw new InvalidOperationException($"Multiple handlers found for message type {MessageTypeKey.Get(key.MessageType)}. Use Publish for multiple handlers.");
127127

128128
var handler = handlersList.First();
129129
if (handler.IsAsync)
130-
throw new InvalidOperationException($"Cannot use synchronous Invoke with async-only handler for message type {key.MessageType.FullName}. Use InvokeAsync instead.");
130+
throw new InvalidOperationException($"Cannot use synchronous Invoke with async-only handler for message type {MessageTypeKey.Get(key.MessageType)}. Use InvokeAsync instead.");
131131

132132
return (mediator, msg, ct) => handler.Handle!(mediator, msg, ct, key.ResponseType);
133133
});
@@ -163,8 +163,7 @@ private PublishAsyncDelegate[] GetAllApplicableHandlers(object message)
163163
}
164164

165165
return allHandlers
166-
.GroupBy(h => $"{h.MessageTypeName}:{h.HandleAsync.Method.DeclaringType?.FullName}:{h.HandleAsync.Method.Name}")
167-
.Select(g => g.First())
166+
.Distinct()
168167
.Select<HandlerRegistration, PublishAsyncDelegate>(h => async (mediator, msg, cancellationToken) => await h.HandleAsync(mediator, msg, cancellationToken, null))
169168
.ToArray();
170169
});

0 commit comments

Comments
 (0)