From 93fa25c1631dc39de1999dad3a5192e30bc6528c Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 15 Aug 2019 17:56:38 +0200 Subject: [PATCH] [skip appveyor] Fixed #4: Unhelpful error message when starting a (parallel) flow before Subscribe has finished Fixed #12: Flow allows request message without Request attribute --- Tapeti.Flow/Default/FlowProvider.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tapeti.Flow/Default/FlowProvider.cs b/Tapeti.Flow/Default/FlowProvider.cs index 22b2ce1..9d64ded 100644 --- a/Tapeti.Flow/Default/FlowProvider.cs +++ b/Tapeti.Flow/Default/FlowProvider.cs @@ -132,12 +132,15 @@ namespace Tapeti.Flow.Default private static ResponseHandlerInfo GetResponseHandlerInfo(ITapetiConfig config, object request, Delegate responseHandler) { + var requestAttribute = request.GetType().GetCustomAttribute(); + if (requestAttribute?.Response == null) + throw new ArgumentException($"Request message {request.GetType().Name} must be marked with the Request attribute and a valid Response type", nameof(request)); + var binding = config.Bindings.ForMethod(responseHandler); if (binding == null) throw new ArgumentException("responseHandler must be a registered message handler", nameof(responseHandler)); - var requestAttribute = request.GetType().GetCustomAttribute(); - if (requestAttribute?.Response != null && !binding.Accept(requestAttribute.Response)) + if (!binding.Accept(requestAttribute.Response)) throw new ArgumentException($"responseHandler must accept message of type {requestAttribute.Response}", nameof(responseHandler)); var continuationAttribute = binding.Method.GetCustomAttribute(); @@ -145,7 +148,7 @@ namespace Tapeti.Flow.Default throw new ArgumentException("responseHandler must be marked with the Continuation attribute", nameof(responseHandler)); if (binding.QueueName == null) - throw new ArgumentException("responseHandler must bind to a valid queue", nameof(responseHandler)); + throw new ArgumentException("responseHandler is not yet subscribed to a queue, TapetiConnection.Subscribe must be called before starting a flow", nameof(responseHandler)); return new ResponseHandlerInfo {