From 3b678e4eb1a987aace4c5912fa443e0c89877519 Mon Sep 17 00:00:00 2001 From: Marius Volkhart Date: Fri, 30 Nov 2018 21:50:13 +0700 Subject: [PATCH] Provide additional information during errors This ought to help developers diagnose where the error occurred. The current stack trace provides no actionable information and requires going through the whole Interface searching for violations. ``` Unhandled Exception: System.ArgumentException: URL has parameter member, but no method parameter matches at Refit.RestMethodInfo.BuildParameterMap(String relativePath, List`1 parameterInfo) in D:\a\1\s\Refit\RestMethodInfo.cs:line 143 at Refit.RestMethodInfo..ctor(Type targetInterface, MethodInfo methodInfo, RefitSettings refitSettings) in D:\a\1\s\Refit\RestMethodInfo.cs:line 64 at Refit.RequestBuilderImplementation`1..ctor(RefitSettings refitSettings) in D:\a\1\s\Refit\RequestBuilderImplementation.cs:line 58 at Refit.RequestBuilderFactory.Create[T](RefitSettings settings) in D:\a\1\s\Refit\RequestBuilderFactory.cs:line 17 at Refit.RequestBuilder.ForType[T](RefitSettings settings) in D:\a\1\s\Refit\RequestBuilder.cs:line 24 at Refit.RestService.For[T](HttpClient client, RefitSettings settings) in D:\a\1\s\Refit\RestService.cs:line 28 at Refit.RestService.For[T](HttpClient client) in D:\a\1\s\Refit\RestService.cs:line 33 at MyCode.Program.Main(String[] args) in /Users/me/Documents/MyCode/MyCode/Program.cs:line 16 ``` --- Refit/RestMethodInfo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Refit/RestMethodInfo.cs b/Refit/RestMethodInfo.cs index d360406ff..f25295913 100644 --- a/Refit/RestMethodInfo.cs +++ b/Refit/RestMethodInfo.cs @@ -94,7 +94,7 @@ public RestMethodInfo(Type targetInterface, MethodInfo methodInfo, RefitSettings var ctParams = methodInfo.GetParameters().Where(p => p.ParameterType == typeof(CancellationToken)).ToList(); if(ctParams.Count > 1) { - throw new ArgumentException("Argument list can only contain a single CancellationToken"); + throw new ArgumentException($"Argument list to method \"{methodInfo.Name}\" can only contain a single CancellationToken"); } CancellationToken = ctParams.FirstOrDefault(); @@ -117,7 +117,7 @@ void VerifyUrlPathIsSane(string relativePath) return; bogusPath: - throw new ArgumentException("URL path must be of the form '/foo/bar/baz'"); + throw new ArgumentException($"URL path {relativePath} must be of the form '/foo/bar/baz'"); } Dictionary BuildParameterMap(string relativePath, List parameterInfo) @@ -137,7 +137,7 @@ Dictionary BuildParameterMap(string relativePath, List or IObservable"); + throw new ArgumentException($"Method \"{methodInfo.Name}\" is invalid. All REST Methods must return either Task or IObservable"); } } }